NFC标签扫描仅触发我的应用程序启动 [英] NFC tag scan only triggers my app to start
问题描述
我有扫描NFC标签的应用程序,收集来自标签的数据和数据发送给服务器。标签上的数据是按以下格式:
1,3,30012,somebodys名
这些标签放置在客户端的房屋为护理人员进行扫描。每次扫描记录他们进入的呼叫。
这一直工作正常为止。我现在的问题是,护理人员必须使用其他应用程序与我们的应用程序,它会扫描不同的NFC标签,上面有不同的数据,并将其发送到另一台服务器。这个应用程序安装在同一台护工的电话。
这其他的应用程序将扫描NFC标签,可能有以下格式上的数据:
ABC | 123?
问题是我怎么能保证当护工扫描我们的标签,只有我们的应用程序启动?
有没有在意向过滤器指定此为我的应用程序的清单的方式?
这是我的清单我的活动。我明白,如果一个Intent启动并有2个应用程序,可以处理一个NFC标签那么列表psented用户$ P $。 Android的文档阻止反对这一点。
先谢谢了。
有一件事我已经注意到了,如果手机主屏幕上,我扫描标签,然后我的应用程序启动。这是好的,如果护理者扫描标签正确
<活动机器人:名字=。NfcscannerActivity
机器人:screenOrientation =肖像>
&所述;意图滤光器>
<作用机器人:名字=android.nfc.action.NDEF_DISCOVERED/>
<类机器人:名字=android.intent.category.DEFAULT/>
<数据机器人:mime类型=text / plain的/>
&所述; /意图滤光器>
&所述;意图滤光器>
<作用机器人:名字=com.carefreegroup.rr3.QR code_ACTION/>
<类机器人:名字=android.intent.category.DEFAULT/>
<数据机器人:mime类型=text / plain的/>
&所述; /意图滤光器>
&所述;意图滤光器>
<作用机器人:名字=android.nfc.action.TECH_DISCOVERED/>
<类机器人:名字=android.intent.category.DEFAULT/>
&所述; /意图滤光器>
&所述;元数据
机器人:名字=android.nfc.action.TECH_DISCOVERED
机器人:资源=@ XML / nfc_tech_filter/>
< /活性GT;
您可以在您的NDEF消息创建一个自定义mime类型,然后创建一个意图过滤器,完全匹配的。这意味着你的应用程序将启动,因为它是最具体的过滤器。
例如:
<意向滤光器>
<作用机器人:名字=android.nfc.action.NDEF_DISCOVERED/>
<类机器人:名字=android.intent.category.DEFAULT/>
<数据机器人:mime类型=应用/ vnd.com.my.app.package.customString/>
&所述; /意图滤光器>
编辑:
另外,如果您不能创建一个自定义的mime类型,那么也许你的程序将创建一个自定义网址?然后,您可以创建自定义URL过滤器来代替:
<意向滤光器>
<作用机器人:名字=android.nfc.action.NDEF_DISCOVERED/>
<类机器人:名字=android.intent.category.DEFAULT/>
<数据
机器人:计划=HTTP
机器人:主机=www.mywebsite.net
机器人:PATH =/ customPathForAction/>
&所述; /意图滤光器>
I have an app that scans NFC tags, collects the data from the tag and sends that data to the server. The data on the tag is in the following format:
1,3,30012,somebodys name
These tags are placed in client's houses for carers to scan. Each scan logs them into a call.
This has been working fine so far. The problem i have now is that the carers must use another app alongside our app which scans a different NFC tag, with different data on it and sends it to a different server. This app is installed on the same carer's phone.
This other app will scan NFC tags that might have data on it in the following format:
abc|123??
The question is how can i ensure that when the carer scans our tag, ONLY our app is launched?
Is there a way in the manifest of specifying this in the intent-filters for my app?
This is what i have in the manifest for my Activity. I understand that if an Intent is launched and there are 2 apps that could process an NFC tag then a list is presented to the user. The Android docs discourage against this.
Thanks in advance.
[Edit] One thing i have noticed, if the phone is on the home screen and i scan a tag, then my app is launched. This is fine if the carer scans the correct tag.
<activity android:name=".NfcscannerActivity"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="com.carefreegroup.rr3.QRCODE_ACTION" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data
android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="@xml/nfc_tech_filter" />
</activity>
You could create a custom mimeType in your NDEF message and then create an intent-filter which matches it exactly. This would mean your app would be launched as it is the most specific filter.
Example:
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/vnd.com.my.app.package.customString" />
</intent-filter>
Edit: Alternatively if you cannot create a custom mimeType then perhaps your utility will create a custom URL? Then you can create a filter for the custom url instead:
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:scheme="http"
android:host="www.mywebsite.net"
android:path="/customPathForAction" />
</intent-filter>
这篇关于NFC标签扫描仅触发我的应用程序启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!