summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@theqtcompany.com>2016-08-03 14:47:19 +0200
committerAlex Blasche <alexander.blasche@qt.io>2016-08-31 14:01:01 +0000
commit8e7d7ac7dcfecd734346e7e8c3a44c59c5558a4c (patch)
treeb9660dbaf637c5e505d4963f2389efe0ea4cac8a
parentdc1e5850237660df4c64c5ed29e5f7824be6ce81 (diff)
Prepare QtNfc for Android Service support
It cannot really be fixed sind Android's NFC API requires Activity objects. We merely ensure that the service case is discovered early, reported accordingly and documented properly. Change-Id: If75856eea3da5c6283a3cb988daffd7a36cc02a7 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
-rw-r--r--src/android/nfc/src/org/qtproject/qt5/android/nfc/QtNfc.java11
-rw-r--r--src/nfc/doc/src/nfc-overview.qdoc3
2 files changed, 11 insertions, 3 deletions
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 47c79f5f..47dcf1bf 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
@@ -64,10 +64,15 @@ public class QtNfc
static public IntentFilter[] m_filters;
static public Activity m_activity;
- static public void setActivity(Activity activity, Object activityDelegate)
+ static public void setContext(Context context)
{
- //Log.d(TAG, "setActivity " + activity);
- m_activity = activity;
+ if (!(context instanceof Activity)) {
+ Log.w(TAG, "NFC only works with Android activities and not in Android services. " +
+ "NFC has been disabled.");
+ return;
+ }
+
+ m_activity = (Activity)context;
m_adapter = NfcAdapter.getDefaultAdapter(m_activity);
if (m_adapter == null) {
//Log.e(TAG, "No NFC available");
diff --git a/src/nfc/doc/src/nfc-overview.qdoc b/src/nfc/doc/src/nfc-overview.qdoc
index ac511471..9628ec49 100644
--- a/src/nfc/doc/src/nfc-overview.qdoc
+++ b/src/nfc/doc/src/nfc-overview.qdoc
@@ -45,6 +45,9 @@ With the Qt NFC API typical use cases are:
The following sections describe how to use Qt NFC C++ classes and QML types for the above use cases.
+\note On Android, Qt Nfc only works in foreground applications. Android services are not supported which is due to
+API limitations on the Android side.
+
\section1 C++ Overview
The C++ API provides access to the full feature set of the Qt NFC API. This section introduces the