summaryrefslogtreecommitdiffstats
path: root/src/nfc/android
diff options
context:
space:
mode:
authorPeter Rustler <peter.rustler@basyskom.com>2015-03-02 15:58:40 +0100
committerAlex Blasche <alexander.blasche@theqtcompany.com>2015-03-18 08:46:35 +0000
commit55aab6b68bf4991fb133b5f7066a07554e3c5b3e (patch)
tree0fa4192391379d04a19f9dce1da46c70e57fe2a8 /src/nfc/android
parentcace1dd0a88245129ebef2e98f13749f2f31fa4f (diff)
Add the feature to get the nfc intent that startet the app
To support this one have to add a AndroidManifest.xml file to the project. In that file an intent filter should be added to get nfc intents while in backround.. The corkboard example was extended to have an example for this new feature. Change-Id: I108afd88f9e5a548d62245591ebef11de8eb0d81 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src/nfc/android')
-rw-r--r--src/nfc/android/androidjninfc.cpp11
-rw-r--r--src/nfc/android/androidjninfc_p.h1
-rw-r--r--src/nfc/android/androidmainnewintentlistener.cpp14
3 files changed, 26 insertions, 0 deletions
diff --git a/src/nfc/android/androidjninfc.cpp b/src/nfc/android/androidjninfc.cpp
index 47e9aabd..4a1c077d 100644
--- a/src/nfc/android/androidjninfc.cpp
+++ b/src/nfc/android/androidjninfc.cpp
@@ -47,6 +47,7 @@ static jclass nfcClass;
static jmethodID startDiscoveryId;
static jmethodID stopDiscoveryId;
static jmethodID isAvailableId;
+static jmethodID getStartIntentId;
static AndroidNfc::MainNfcNewIntentListener mainListener;
@@ -102,6 +103,15 @@ bool stopDiscovery()
return aenv.jniEnv->CallStaticBooleanMethod(nfcClass, stopDiscoveryId);
}
+jobject getStartIntent()
+{
+ AttachedJNIEnv aenv;
+ if (!aenv.jniEnv)
+ return NULL;
+
+ return aenv.jniEnv->CallStaticObjectMethod(nfcClass, getStartIntentId);
+}
+
bool registerListener(AndroidNfcListenerInterface *listener)
{
return mainListener.registerListener(listener);
@@ -170,6 +180,7 @@ Q_DECL_EXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void * /*reserved*/)
GET_AND_CHECK_STATIC_METHOD(startDiscoveryId, nfcClass, "start", "()Z");
GET_AND_CHECK_STATIC_METHOD(stopDiscoveryId, nfcClass, "stop", "()Z");
GET_AND_CHECK_STATIC_METHOD(isAvailableId, nfcClass, "isAvailable", "()Z");
+ GET_AND_CHECK_STATIC_METHOD(getStartIntentId, nfcClass, "getStartIntent", "()Landroid/content/Intent;");
javaVM = vm;
return JNI_VERSION_1_6;
diff --git a/src/nfc/android/androidjninfc_p.h b/src/nfc/android/androidjninfc_p.h
index 9ec366ee..9e402abd 100644
--- a/src/nfc/android/androidjninfc_p.h
+++ b/src/nfc/android/androidjninfc_p.h
@@ -64,6 +64,7 @@ private:
bool startDiscovery();
bool stopDiscovery();
+jobject getStartIntent();
bool isAvailable();
bool registerListener(AndroidNfcListenerInterface *listener);
bool unregisterListener(AndroidNfcListenerInterface *listener);
diff --git a/src/nfc/android/androidmainnewintentlistener.cpp b/src/nfc/android/androidmainnewintentlistener.cpp
index a2bab47a..c8f16572 100644
--- a/src/nfc/android/androidmainnewintentlistener.cpp
+++ b/src/nfc/android/androidmainnewintentlistener.cpp
@@ -33,6 +33,7 @@
#include "androidmainnewintentlistener_p.h"
+#include <QtGui/QGuiApplication>
QT_BEGIN_ANDROIDNFC_NAMESPACE
@@ -65,6 +66,19 @@ bool MainNfcNewIntentListener::handleNewIntent(JNIEnv *env, jobject intent)
bool MainNfcNewIntentListener::registerListener(AndroidNfcListenerInterface *listener)
{
+ static bool firstListener = true;
+ if (firstListener) {
+ AttachedJNIEnv aenv;
+ if (aenv.jniEnv) {
+ jobject intent = AndroidNfc::getStartIntent();
+ if (intent) {
+ jobject newIntentRef = aenv.jniEnv->NewGlobalRef(intent);
+ listener->newIntent(newIntentRef);
+ }
+ }
+ paused = static_cast<QGuiApplication*>(QGuiApplication::instance())->applicationState() != Qt::ApplicationActive;
+ }
+ firstListener = false;
listenersLock.lockForWrite();
if (!listeners.contains(listener))
listeners.push_back(listener);