简体   繁体   English

如何更改打开应用程序的默认方式

[英]How to change the default way to open application

I wrote an application about NFC in android,but I have a problem. 我在android上写了一个有关NFC的应用程序,但是我有一个问题。 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. 当我将NFC标签放在靠近手机的地方时,将出现一个对话框,让我选择要从NFC标签读取信息的应用程序。 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. 但是我不希望该对话框只是希望当NFC标签靠近手机时,我编写的应用程序会自动打开。 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. Android确定自动打开哪个应用程序的唯一方法是Android是否可以读取标签内容。 This is only possible when the tag follows one of the NFC Forum Type Tag standards and contains an NDEF message. 仅当标签遵循NFC论坛类型标签标准之一并且包含NDEF消息时,才有可能。 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. 在这种情况下,Android将发送ACTION_NDEF_DISCOVERED意图,其中包含基于标记内容的数据,例如URI或MIME类型。 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. 如果MIME类型或URI是唯一的,则您的应用程序将是唯一匹配的应用程序,并会自动打开。

If the NFC tags you are working with do not contain an NDEF message, you are essentially out of luck. 如果您正在使用的NFC标签不包含NDEF消息,则说明您基本上不走运。 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. Android无法确定比标签技术更具体的内容,并且经常会有多个应用程序订阅了这些意图。 So an app chooser will be presented to the user to pick the right app. 因此,将向用户显示一个应用选择器,以选择合适的应用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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