NFC tag scan only triggers my app to start

前端 未结 1 1531
离开以前
离开以前 2021-01-15 19:18

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,3001         


        
相关标签:
1条回答
  • 2021-01-15 20:15

    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>
    
    0 讨论(0)
提交回复
热议问题