diff options
author | Alex Blasche <alexander.blasche@theqtcompany.com> | 2016-04-06 12:52:53 +0200 |
---|---|---|
committer | Alex Blasche <alexander.blasche@theqtcompany.com> | 2016-04-13 07:47:14 +0000 |
commit | 9e58b52f6ba0e5cdbcb305175198f07db27b59bd (patch) | |
tree | 78c172acb683cb6c2cd243055814aba82b4e42fe /src/nfc | |
parent | aecf1408552a440b81b1157c4f701533833c09c8 (diff) |
Android: Suppress failed connect/close attempts due to targetLost detection
Android does not provide an API to detect when an NFC tag is removed
from the vincinity. To detect such a case the Android implementation
uses active polling. During each polling cycle the implementation
connects and disconnects from the tag. If it failed, the tag is assumed
to have been removed from the vincinity.
Such failed attempts cause an IOException which are printed to stderr. This
is confusing as the developer might mistake them for some other serious
problem. This change suppresses all related warnings.
Change-Id: I95cf57076139e7d0a5ad31d4cc770a81ced12242
Reviewed-by: Frank Meerkoetter <frank.meerkoetter@basyskom.com>
Reviewed-by: Peter Rustler <peter.rustler@basyskom.com>
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src/nfc')
-rw-r--r-- | src/nfc/qnearfieldtarget_android.cpp | 9 | ||||
-rw-r--r-- | src/nfc/qnearfieldtarget_android_p.h | 2 |
2 files changed, 6 insertions, 5 deletions
diff --git a/src/nfc/qnearfieldtarget_android.cpp b/src/nfc/qnearfieldtarget_android.cpp index 891ce3fc..850f8b4d 100644 --- a/src/nfc/qnearfieldtarget_android.cpp +++ b/src/nfc/qnearfieldtarget_android.cpp @@ -304,12 +304,12 @@ void NearFieldTarget::checkIsTargetLost() QString techStr = m_techList.first(); QAndroidJniObject tagTech = getTagTechnology(techStr); tagTech.callMethod<void>("connect"); - if (catchJavaExceptions()) { + if (catchJavaExceptions(false)) { handleTargetLost(); return; } tagTech.callMethod<void>("close"); - if (catchJavaExceptions()) + if (catchJavaExceptions(false)) handleTargetLost(); } @@ -436,11 +436,12 @@ QByteArray NearFieldTarget::jbyteArrayToQByteArray(const jbyteArray &byteArray) return resultArray; } -bool NearFieldTarget::catchJavaExceptions() const +bool NearFieldTarget::catchJavaExceptions(bool verbose) const { QAndroidJniEnvironment env; if (env->ExceptionCheck()) { - env->ExceptionDescribe(); + if (verbose) + env->ExceptionDescribe(); env->ExceptionClear(); return true; } diff --git a/src/nfc/qnearfieldtarget_android_p.h b/src/nfc/qnearfieldtarget_android_p.h index 73f2499c..d0304ec4 100644 --- a/src/nfc/qnearfieldtarget_android_p.h +++ b/src/nfc/qnearfieldtarget_android_p.h @@ -93,7 +93,7 @@ protected: void handleTargetLost(); QAndroidJniObject getTagTechnology(const QString &tech) const; QByteArray jbyteArrayToQByteArray(const jbyteArray &byteArray) const; - bool catchJavaExceptions() const; + bool catchJavaExceptions(bool verbose = true) const; protected: QAndroidJniObject m_intent; |