diff options
author | Alex Blasche <alexander.blasche@theqtcompany.com> | 2014-12-08 11:19:16 +0100 |
---|---|---|
committer | Alex Blasche <alexander.blasche@theqtcompany.com> | 2014-12-10 12:47:40 +0100 |
commit | 026714701477706231298e92878286930baf3948 (patch) | |
tree | 6a2cd84e6d91dbf9efdd8f26884357ac0a931d94 /examples/nfc/poster | |
parent | 994934b36bcfa74da8975ec31da528ddded50e16 (diff) |
Enable automatic tag polling if message handler is not supported.
All examples have used message handler registration so far. That's
not always supported on all platforms. Neard is one of those
platforms against which this this was verified.
This patch converts some examples to use manual target detection
if handler registration fails.
Change-Id: Icfd8b7c695e63351a45b867fd69e9fc5fefb9360
Reviewed-by: Martin Leutelt <martin.leutelt@basyskom.com>
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'examples/nfc/poster')
-rw-r--r-- | examples/nfc/poster/poster.qml | 46 |
1 files changed, 37 insertions, 9 deletions
diff --git a/examples/nfc/poster/poster.qml b/examples/nfc/poster/poster.qml index e2c67dd9..34181017 100644 --- a/examples/nfc/poster/poster.qml +++ b/examples/nfc/poster/poster.qml @@ -38,7 +38,7 @@ ** ****************************************************************************/ -import QtQuick 2.0 +import QtQuick 2.3 import QtNfc 5.2 Rectangle { @@ -48,6 +48,19 @@ Rectangle { NearField { id: nearfield + property bool requiresManualPolling: false + + onPollingChanged: { + if (!polling && requiresManualPolling) + polling = true; //restart polling + } + + Component.onCompleted: { + if (!polling) { + requiresManualPolling = true; + polling = true; + } + } filter: [ NdefFilter { type: "U"; typeNameFormat: NdefRecord.NfcRtd; minimum: 1; maximum: 1 }, @@ -61,17 +74,32 @@ Rectangle { var currentLocaleMatch = NdefTextRecord.LocaleMatchedNone; var i; + var found = false; for (i = 0; i < messageRecords.length; ++i) { - if (messageRecords[i].recordType == "urn:nfc:wkt:T") { - if (messageRecords[i].localeMatch > currentLocaleMatch) { - currentLocaleMatch = messageRecords[i].localeMatch; - posterText.text = messageRecords[i].text; + switch (messageRecords[i].typeNameFormat) { + case NdefRecord.NfcRtd: + if (messageRecords[i].type === "T") { + if (messageRecords[i].localeMatch > currentLocaleMatch) { + currentLocaleMatch = messageRecords[i].localeMatch; + posterText.text = messageRecords[i].text; + found = true; + } + + } else if (messageRecords[i].type === "U") { + posterUrl.text = messageRecords[i].uri; + found = true; + } + break; + case NdefRecord.Mime: + if (messageRecords[i].type.startsWith("image/")) { + posterImage.source = messageRecords[i].uri; + found = true; } - } else if (messageRecords[i].recordType == "urn:nfc:wkt:U") { - posterUrl.text = messageRecords[i].uri; - } else if (messageRecords[i].recordType.substr(0, 19) == "urn:nfc:mime:image/") { - posterImage.source = messageRecords[i].uri; + break; } + + if (!found) + console.warn("Unknown NFC tag detected. Cannot display content.") } root.state = "show"; |