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; 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 kBytesSo, the question is: "What happens to the signals, why don't they fire?"