NFC. Start a activity when scanning NDEF message

前端 未结 2 1010
清歌不尽
清歌不尽 2021-01-07 10:51

I\'m trying to start a activity when my smartphone scans an NDEF message. This is my manifest:




        
相关标签:
2条回答
  • 2021-01-07 11:16

    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?

    0 讨论(0)
  • 2021-01-07 11:25

    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.

    0 讨论(0)
提交回复
热议问题