NFC Problem on android

  • 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;
        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)
    void MyNFC::targetLost(QNearFieldTarget *target)
        if (target)
        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="" android:label="-- %%INSERT_APP_NAME%% --">
            <activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation" android:name="" android:label="-- %%INSERT_APP_NAME%% --" android:screenOrientation="landscape" android:launchMode="singleTop">
                    <action android:name="android.intent.action.MAIN"/>
                    <category android:name="android.intent.category.LAUNCHER"/>

    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?"

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.