NFC. Start a activity when scanning NDEF message

旧巷老猫 提交于 2019-12-01 01:12:33

The trick is that NFC Forum external type names are case-insensitive. However, Android's intent filter system is case-SENSITIVE. Therefore, you must always use ALL lower-case external type names in your intent filters:

<activity android:name="com.example.androidbeam.ReceiverNDEFActivity" >
    <intent-filter>
        <action android:name="android.nfc.action.NDEF_DISCOVERED" />
        <category android:name="android.intent.category.DEFAULT" />
        <data
            android:scheme="vnd.android.nfc"
            android:host="ext"
            android:pathPrefix="/com.example:externaltype" />
    </intent-filter>
</activity>

Note that the NdefRecord.createExternal(...) method will automatically convert all type names to lower-case spelling.

The manifest looks pretty much ok I think. Maybe you can try adding

android:exported="true"

to the activity that should receive the NFC-scanning intent.

    <activity android:name="com.example.androidbeam.ReceiverNDEFActivity" >
        <intent-filter>
            <action android:name="android.nfc.action.NDEF_DISCOVERED"
            android:exported="true"
            />
            <category android:name="android.intent.category.DEFAULT" />
            <data
                android:host="ext"
                android:pathPrefix="/com.example:externalType"
                android:scheme="vnd.android.nfc" />
        </intent-filter>
    </activity>

Are you using a NFC-tag to scan from?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!