summaryrefslogtreecommitdiffstats
path: root/src/android
diff options
context:
space:
mode:
authorLars Schmertmann <Lars.Schmertmann@governikus.de>2017-01-26 13:07:26 +0100
committerLars Schmertmann <lars.schmertmann@governikus.de>2017-01-27 09:20:35 +0000
commit6b69a54a02c5deb61eaceec1c432a970d4f1da90 (patch)
tree4e030f0e7698c6e5495563191aa6e798929d5382 /src/android
parent3cf6938938c7d56f04b43cfd951a2d6b31db7ee1 (diff)
Allow using nfc when running as a service
With this change it will be possible to use a tag injected from outside when running as a service. Intent newIntent = new Intent(); newIntent.putExtra(NfcAdapter.EXTRA_TAG, tag); QtNative.onNewIntent(newIntent); Task-number: QTBUG-57646 Change-Id: I628d4357f023a0926e7d61914b39278342ac7161 Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/android')
-rw-r--r--src/android/nfc/src/org/qtproject/qt5/android/nfc/QtNfc.java26
1 files changed, 15 insertions, 11 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 4f39eb47..25c560f8 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
@@ -62,22 +62,25 @@ public class QtNfc
static public NfcAdapter m_adapter = null;
static public PendingIntent m_pendingIntent = null;
static public IntentFilter[] m_filters;
- static public Activity m_activity;
+ static public Context m_context = null;
+ static public Activity m_activity = null;
static public void setContext(Context context)
{
- if (!(context instanceof Activity)) {
- Log.w(TAG, "NFC only works with Android activities and not in Android services. " +
- "NFC has been disabled.");
+ m_context = context;
+ if (context instanceof Activity) m_activity = (Activity) context;
+ m_adapter = NfcAdapter.getDefaultAdapter(context);
+
+ if (m_activity == null) {
+ Log.w(TAG, "New NFC tags will only be recognized with Android activities and not with Android services.");
return;
}
- m_activity = (Activity)context;
- m_adapter = NfcAdapter.getDefaultAdapter(m_activity);
if (m_adapter == null) {
//Log.e(TAG, "No NFC available");
return;
}
+
m_pendingIntent = PendingIntent.getActivity(
m_activity,
0,
@@ -103,7 +106,8 @@ public class QtNfc
static public boolean start()
{
- if (m_adapter == null) return false;
+ if (m_adapter == null || m_activity == null) return false;
+
m_activity.runOnUiThread(new Runnable() {
public void run() {
//Log.d(TAG, "Enabling NFC");
@@ -136,7 +140,8 @@ public class QtNfc
static public boolean stop()
{
- if (m_adapter == null) return false;
+ if (m_adapter == null || m_activity == null) return false;
+
m_activity.runOnUiThread(new Runnable() {
public void run() {
//Log.d(TAG, "Disabling NFC");
@@ -153,13 +158,11 @@ public class QtNfc
static public boolean isAvailable()
{
- if (m_activity == null) return false;
-
- m_adapter = NfcAdapter.getDefaultAdapter(m_activity);
if (m_adapter == null) {
//Log.e(TAG, "No NFC available (Adapter is null)");
return false;
}
+
return m_adapter.isEnabled();
}
@@ -167,6 +170,7 @@ public class QtNfc
{
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()) ||