其他分享
首页 > 其他分享> > 找到自定义格式的nfc标签后,打开我的应用

找到自定义格式的nfc标签后,打开我的应用

作者:互联网

我正在制作一个用于库存管理的应用程序.每个stock_item将具有带有唯一标识符和custom_format的标签.
像这样:

stock_manager_pro:stock_item:12345

要么

stock_manager_pro:user:john

当设备发现标签的内容以stock_manager_pro开头的标签时,我想使我的应用自动打开

使用此代码,当手机发现带有纯文本内容的nfc标签时,我的应用程序即会打开,但我希望能够过滤客户文本.

        <intent-filter>
            <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
            <data android:mimeType="text/plain" />
            <category android:name="android.intent.category.DEFAULT"/>
        </intent-filter>

解决方法:

我正在处理相同的问题…
我发现您应该创建自己的自定义MIME类型.
在清单文件中,您只需删除

<action android:name="android.nfc.action.NDEF_DISCOVERED"/> 

例如

<intent-filter >
   <!--  <action   android:name="android.nfc.action.NDEF_DISCOVERED" />-->
   <category android:name="android.intent.category.DEFAULT" />
   <data android:mimeType="application/vnd.com.nfctagwriter" />
</intent-filter>

标签:android-intent,android-activity,nfc,intentfilter,android
来源: https://codeday.me/bug/20191201/2078653.html