简体   繁体   中英

How to change the default way to open application

I wrote an application about NFC in android,but I have a problem. When I take a NFC tag close to the mobile phone, a dialog box will appear to let me choose which application to read the information from the NFC tag. But I don't want this dialog box I just want that when a NFC tag is close to the mobile phone, the application I wrote will automatically open. I tried to modify the code to:

<intent-filter android:priority = "100">
    <action android:name="android.nfc.action.TECH_DISCOVERED" />                
</intent-filter>
<meta-data android:name="android.nfc.action.TECH_DISCOVERED"
     android:resource="@xml/filter_nfc"/>   

当您设置唯一的uri ..时,它将打开您的应用程序,而不是其他应用程序。http: //developer.android.com/guide/topics/nfc/nfc.html#ndef

The only way for Android to determine which app to open automatically, is if Android can read itself the contents of the tag. This is only possible when the tag follows one of the NFC Forum Type Tag standards and contains an NDEF message. In that case, Android will send an ACTION_NDEF_DISCOVERED intent, containing data that is based on the contents of the tag, such as a URI or a MIME type. Your app can declare an intent filter based on this to receive such an intent. If the MIME type or URI is unique, your app will be the only one that matches and will automatically be opened.

If the NFC tags you are working with do not contain an NDEF message, you are essentially out of luck. There is no way for Android to determine anything more specific than the technology of the tag and there will often be multiple apps that have subscribed to such intents. So an app chooser will be presented to the user to pick the right app.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM