Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. NFC Problem on android
QtWS25 Last Chance

NFC Problem on android

Scheduled Pinned Locked Moved Unsolved General and Desktop
androidnfc
1 Posts 1 Posters 696 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mhusari
    wrote on last edited by mhusari
    #1

    Hello,

    I have a problem with NFC on android, QNearFieldManager seems to work ok but I do not get the signals. I suspect that the problem is within android and/or AndroidManifest.xml since rest of the code is very simple. Please advice :)

    Here is relevant part of main.cpp

    #include "mynfc.h"
    
    int main(int argc, char *argv[])
    {
        QGuiApplication app(argc, argv);
    
        qmlRegisterType<MyNFC>("omat.kirjastot.nfc", 1, 0, "MyNFC");
    
        QQmlApplicationEngine engine;
        engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    
        return app.exec();
    }
    
    

    Here is the code from my constructor that initiates the manager and connects the signals:

    MyNFC::MyNFC(QObject *parent) : QObject(parent)
    {
        manager = new QNearFieldManager(this);
    
    // Both of these return "true"
        qDebug() << "manager->isAvailable(); == " << manager->isAvailable();
        qDebug() << "manager->startTargetDetection(); == " << manager->startTargetDetection();
    
    // These signals I am waiting for, but they never fire
        connect(manager, SIGNAL(targetDetected(QNearFieldTarget*)),
                this, SLOT(targetDetected(QNearFieldTarget*)));
        connect(manager, SIGNAL(targetLost(QNearFieldTarget*)),
                this, SLOT(targetLost(QNearFieldTarget*)));
    
    }
    

    Here are the slots for those signals:

    void MyNFC::targetDetected(QNearFieldTarget *target)
    {
        qDebug() << "tag found....";
    
        if (!target)
            return;
    }
    
    void MyNFC::targetLost(QNearFieldTarget *target)
    {
        if (target)
            target->deleteLater();
    
        qDebug() << "tag lost....";
    }
    

    Here is some of what I have in AndroidManifest.xml

        <uses-feature android:name="android.hardware.nfc" android:required="true"/>
        <uses-permission android:name="android.permission.NFC"/>
        <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="16"/>
        <application android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" android:label="-- %%INSERT_APP_NAME%% --">
            <activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation" android:name="org.qtproject.qt5.android.bindings.QtActivity" android:label="-- %%INSERT_APP_NAME%% --" android:screenOrientation="landscape" android:launchMode="singleTop">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN"/>
                    <category android:name="android.intent.category.LAUNCHER"/>
                </intent-filter>
            </activity>
        </application>
    

    Should I post all xml file contents?

    I suppose "intent-filter" is unnecessary for my app as I do not want my app to start on read event. I just want to react to nfc/tag-discovery while app is "focused".

    tag that I am trying to read is read fine on another android app, it reports these values:

    Type: ISO 14443-3A
    Serial number: 20:71:E5:16
    Technologies available: NfcA
    Memory information: 1 kBytes

    So, the question is: "What happens to the signals, why don't they fire?"

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved