diff options
author | Peter Rustler <peter.rustler@basyskom.com> | 2015-03-02 15:58:40 +0100 |
---|---|---|
committer | Alex Blasche <alexander.blasche@theqtcompany.com> | 2015-03-18 08:46:35 +0000 |
commit | 55aab6b68bf4991fb133b5f7066a07554e3c5b3e (patch) | |
tree | 0fa4192391379d04a19f9dce1da46c70e57fe2a8 | |
parent | cace1dd0a88245129ebef2e98f13749f2f31fa4f (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>
-rw-r--r-- | examples/nfc/corkboard/android/AndroidManifest.xml | 61 | ||||
-rw-r--r-- | examples/nfc/corkboard/corkboard.pro | 7 | ||||
-rw-r--r-- | src/android/nfc/src/org/qtproject/qt5/android/nfc/QtNfc.java | 14 | ||||
-rw-r--r-- | src/nfc/android/androidjninfc.cpp | 11 | ||||
-rw-r--r-- | src/nfc/android/androidjninfc_p.h | 1 | ||||
-rw-r--r-- | src/nfc/android/androidmainnewintentlistener.cpp | 14 | ||||
-rw-r--r-- | src/nfc/nfc.pro | 2 |
7 files changed, 109 insertions, 1 deletions
diff --git a/examples/nfc/corkboard/android/AndroidManifest.xml b/examples/nfc/corkboard/android/AndroidManifest.xml new file mode 100644 index 00000000..e921e2b1 --- /dev/null +++ b/examples/nfc/corkboard/android/AndroidManifest.xml @@ -0,0 +1,61 @@ +<?xml version="1.0"?> +<manifest package="org.qtproject.example" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.0" android:versionCode="1" android:installLocation="auto"> + <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|locale|fontScale|keyboard|keyboardHidden|navigation" android:name="org.qtproject.qt5.android.bindings.QtActivity" android:label="-- %%INSERT_APP_NAME%% --" android:screenOrientation="unspecified" android:launchMode="singleTop"> + <intent-filter> + <action android:name="android.intent.action.MAIN"/> + <category android:name="android.intent.category.LAUNCHER"/> + </intent-filter> + <intent-filter> + <action android:name="android.nfc.action.NDEF_DISCOVERED"/> + <category android:name="android.intent.category.DEFAULT"/> + <data android:mimeType="text/plain"/> + </intent-filter> + <meta-data android:name="android.app.lib_name" android:value="-- %%INSERT_APP_LIB_NAME%% --"/> + <meta-data android:name="android.app.qt_sources_resource_id" android:resource="@array/qt_sources"/> + <meta-data android:name="android.app.repository" android:value="default"/> + <meta-data android:name="android.app.qt_libs_resource_id" android:resource="@array/qt_libs"/> + <meta-data android:name="android.app.bundled_libs_resource_id" android:resource="@array/bundled_libs"/> + <!-- Deploy Qt libs as part of package --> + <meta-data android:name="android.app.bundle_local_qt_libs" android:value="-- %%BUNDLE_LOCAL_QT_LIBS%% --"/> + <meta-data android:name="android.app.bundled_in_lib_resource_id" android:resource="@array/bundled_in_lib"/> + <meta-data android:name="android.app.bundled_in_assets_resource_id" android:resource="@array/bundled_in_assets"/> + <!-- Run with local libs --> + <meta-data android:name="android.app.use_local_qt_libs" android:value="-- %%USE_LOCAL_QT_LIBS%% --"/> + <meta-data android:name="android.app.libs_prefix" android:value="/data/local/tmp/qt/"/> + <meta-data android:name="android.app.load_local_libs" android:value="-- %%INSERT_LOCAL_LIBS%% --"/> + <meta-data android:name="android.app.load_local_jars" android:value="-- %%INSERT_LOCAL_JARS%% --"/> + <meta-data android:name="android.app.static_init_classes" android:value="-- %%INSERT_INIT_CLASSES%% --"/> + <!-- Messages maps --> + <meta-data android:value="@string/ministro_not_found_msg" android:name="android.app.ministro_not_found_msg"/> + <meta-data android:value="@string/ministro_needed_msg" android:name="android.app.ministro_needed_msg"/> + <meta-data android:value="@string/fatal_error_msg" android:name="android.app.fatal_error_msg"/> + <!-- Messages maps --> + + <!-- Splash screen --> + <!-- + <meta-data android:name="android.app.splash_screen_drawable" android:resource="@drawable/logo"/> + --> + <!-- Splash screen --> + + <!-- Background running --> + <!-- Warning: changing this value to true may cause unexpected crashes if the + application still try to draw after + "applicationStateChanged(Qt::ApplicationSuspended)" + signal is sent! --> + <meta-data android:name="android.app.background_running" android:value="false"/> + <!-- Background running --> + </activity> + </application> + <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="14"/> + <supports-screens android:largeScreens="true" android:normalScreens="true" android:anyDensity="true" android:smallScreens="true"/> + + <!-- The following comment will be replaced upon deployment with default permissions based on the dependencies of the application. + Remove the comment if you do not require these default permissions. --> + <!-- %%INSERT_PERMISSIONS --> + + <!-- The following comment will be replaced upon deployment with default features based on the dependencies of the application. + Remove the comment if you do not require these default features. --> + <!-- %%INSERT_FEATURES --> + +</manifest> diff --git a/examples/nfc/corkboard/corkboard.pro b/examples/nfc/corkboard/corkboard.pro index d6247032..8c9b05b2 100644 --- a/examples/nfc/corkboard/corkboard.pro +++ b/examples/nfc/corkboard/corkboard.pro @@ -12,3 +12,10 @@ RESOURCES += \ OTHER_FILES += \ corkboards.qml \ Mode.qml + +android:!android-no-sdk { +OTHER_FILES += \ + android/AndroidManifest.xml + +ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android +} diff --git a/src/android/nfc/src/org/qtproject/qt5/android/nfc/QtNfc.java b/src/android/nfc/src/org/qtproject/qt5/android/nfc/QtNfc.java index ec1b6fa9..566489c8 100644 --- a/src/android/nfc/src/org/qtproject/qt5/android/nfc/QtNfc.java +++ b/src/android/nfc/src/org/qtproject/qt5/android/nfc/QtNfc.java @@ -149,4 +149,18 @@ public class QtNfc } return m_adapter.isEnabled(); } + + static public Intent getStartIntent() + { + Log.d(TAG, "getStartIntent"); + if (m_activity == null) return null; + Intent intent = m_activity.getIntent(); + if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(intent.getAction()) || + NfcAdapter.ACTION_TECH_DISCOVERED.equals(intent.getAction()) || + NfcAdapter.ACTION_TAG_DISCOVERED.equals(intent.getAction())) { + return intent; + } else { + return null; + } + } } 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); diff --git a/src/nfc/nfc.pro b/src/nfc/nfc.pro index 9ef57dad..65a746d9 100644 --- a/src/nfc/nfc.pro +++ b/src/nfc/nfc.pro @@ -153,7 +153,7 @@ CONFIG(blackberry) { ANDROID_JAR_DEPENDENCIES = \ jar/QtNfc.jar:org.qtproject.qt5.android.nfc.QtNfc DEFINES += ANDROID_NFC - QT += core-private + QT += core-private gui PRIVATE_HEADERS += \ qllcpserver_android_p.h \ |