由主要行动(从AAR)启动的应用程序,而不是NDEF发现 [英] Application launched by Action Main (from AAR) instead of NDEF Discovered

查看:227
本文介绍了由主要行动(从AAR)启动的应用程序,而不是NDEF发现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过扫描标签来启动我的应用程序,但我得到的意图被发现,因为我想行动主要,而不是NDEF。

I'm trying to launch my application by scanning a tag, but the intent I get is the action Main and not the NDEF Discovered as I would like.

下面是我的code我用写NdefMessage:

Here is my code I use to write the NdefMessage :

NdefRecord aar = NdefRecord.createApplicationRecord("com.example.mynfc");
NdefRecord record = createUriRecord("www.stackoverflow.com");
NdefMessage message = new NdefMessage(new NdefRecord[]{record, aar});

与createUriRecord:

with the createUriRecord :

private NdefRecord createUriRecord(String text){
    String uniqueId = text.substring(4);      
    byte[] uriField = uniqueId.getBytes(Charset.forName("US-ASCII"));  
    byte[] payload = new byte[uriField.length+1];                                                                       //add 1 for the URI Prefix  
    payload[0] = 0x01;                                                                                                  //prefixes http://www. to the URI  
    System.arraycopy(uriField, 0, payload, 1, uriField.length);                                                         //appends URI to payload  
    NdefRecord uriRecord = new NdefRecord(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_URI, new byte[0], payload);
    return uriRecord;
}

这里是清单的部分意图过滤器:

And here is the part of the manifest with the intent filter :

   <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppBaseTheme" >
    <activity
        android:name="com.example.mynfc.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.nfc.action.NDEF_DISCOVERED" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="*/*" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.nfc.action.TECH_DISCOVERED" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>

        <meta-data
            android:name="android.nfc.action.TECH_DISCOVERED"
            android:resource="@xml/techs" />

        <intent-filter>
            <action android:name="android.nfc.action.TAG_DISCOVERED" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

我是什么做错了吗? AAR的记录是第二名,而意图过滤考虑到所有MIME类型。 THX的帮助

What am I doing wrong ? The aar record is placed 2nd, and the intent filter takes into account all mime types. thx for the help

推荐答案

您正在创建一个URI的类型的记录,同时过滤的MIME类型的记录。筛选URI类型的记录来代替。除此之外,URI记录的有效载荷应以方案开始,例如http://。(否则过滤器将不会匹配)

You are creating an URI-type record while filtering for MIME-type records. Filter for URI-type records instead. Besides that, the URI record payload should start with a scheme, such as "http://" (otherwise the filter will never match).

这篇关于由主要行动(从AAR)启动的应用程序,而不是NDEF发现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆