From 3bc0616eb9110959a36ed4746600e6069e4a9392 Mon Sep 17 00:00:00 2001 From: Peter Rustler Date: Mon, 2 Mar 2015 11:10:33 +0100 Subject: Catch the exception for disableForegroundDispatch for Android In Android Nfc disableForegroundDispatch must be called while the activity is still in foreground. We catch the thrown exception if we do call disableForegroundDispatch while we are in background. Change-Id: I396ee3fcb7c7ea835d7d5ed2cb31bf0a8cabb0a8 Reviewed-by: Alex Blasche --- src/android/nfc/src/org/qtproject/qt5/android/nfc/QtNfc.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src') 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 e2c14431..ec1b6fa9 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 @@ -115,7 +115,7 @@ public class QtNfc try { m_adapter.enableForegroundDispatch(m_activity, m_pendingIntent, filters, techList); } catch(IllegalStateException e) { - // On Android we must call enableForegroundDisplatch when the activity is in forground, only. + // On Android we must call enableForegroundDispatch when the activity is in foreground, only. Log.d(TAG, "enableForegroundDispatch failed: " + e.toString()); } } @@ -129,7 +129,12 @@ public class QtNfc m_activity.runOnUiThread(new Runnable() { public void run() { //Log.d(TAG, "Disabling NFC"); - m_adapter.disableForegroundDispatch(m_activity); + try { + m_adapter.disableForegroundDispatch(m_activity); + } catch(IllegalStateException e) { + // On Android we must call disableForegroundDispatch when the activity is in foreground, only. + Log.d(TAG, "disableForegroundDispatch failed: " + e.toString()); + } } }); return true; -- cgit v1.2.3