三星Nexus S vs HTC - NFC Intent Filter + AAR

时间:2012-10-02 18:20:41

标签: android nfc intentfilter ndef android-applicationrecord

我将AAR保存在我的NFC标签上。 如果我使用Nexus S(Android 4.1.1)扫描TAG,我会得到 NfcAdapter.ACTION_NDEF_DISCOVERED和NFCReaderActivity直接启动。

如果我对HTC X(Android 4.0.3)做同样的事情,那么应用程序会启动,但我只是得到了 android.intent.action.MAIN,因此NFCReaderActivity不显示,并且不扫描标签。

这适用于三星Nexus S,但不适用于HTC:

<activity android:name=".activities.NFCWriterActivity"></activity>
<activity android:name=".activities.NFCReaderActivity">
        <intent-filter>
          <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
          <category android:name="android.intent.category.DEFAULT"/>
        </intent-filter>              
</activity>
<activity android:name=".activities.NFCBeamActivity">        
</activity>
<activity android:name=".activities.WifiManagerActivity"></activity>
<activity android:name=".activities.WifiConfiguratorActivity"></activity>
<activity android:name=".activities.TagWriterOptionsActivity"></activity>
<activity android:name=".activities.WifiScannerTagActivity"></activity>
<activity android:name=".activities.WifiScannerActivity"></activity>  
<activity android:name=".activities.WifiListActivity">

</activity>   

这是我的活动和过滤器。

有人有想法吗?


修改

这适用于HTC,但不适用于Samsung Nexus S:

<activity android:name=".activities.NFCWriterActivity"></activity>
<activity android:name=".activities.NFCReaderActivity">
        <intent-filter>
          <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
          <category android:name="android.intent.category.DEFAULT"/>
          <data android:mimeType="application/vnd.wfa.wsc" />
        </intent-filter>              
</activity>
<activity android:name=".activities.NFCBeamActivity">    

</activity>
<activity android:name=".activities.WifiManagerActivity"></activity>
<activity android:name=".activities.WifiConfiguratorActivity"></activity>
<activity android:name=".activities.TagWriterOptionsActivity"></activity>
<activity android:name=".activities.WifiScannerTagActivity"></activity>
<activity android:name=".activities.WifiScannerActivity"></activity>  
<activity android:name=".activities.WifiListActivity"></activity>   

这里我得到了以下异常@ HTC - 也许这是我不知道的问题: 堆栈:

D/AudioTrack( 3938): stop 0x1601940
D/AudioFlinger(  142): releasing 231 from 3938
D/AudioTrack( 3938): AudioTrack destructor X
D/power   (  277): Already locked performance.
W/CpuWake (  277): >>acquireCpuPerfWakeLock!
W/CpuWake (  277): <<acquireCpuPerfWakeLock!
E/ActivityManager(  277): startLaunchActivity get appname failed
E/ActivityManager(  277): java.lang.NullPointerException
E/ActivityManager(  277):   at com.android.server.am.ActivityStack.startLaunchActivity(ActivityStack.java:4831)
E/ActivityManager(  277):   at com.android.server.am.ActivityStack.startActivityMayWait(ActivityStack.java:3352)
E/ActivityManager(  277):   at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:2509)
E/ActivityManager(  277):   at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:131)
E/ActivityManager(  277):   at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:1751)
E/ActivityManager(  277):   at android.os.Binder.execTransact(Binder.java:338)
E/ActivityManager(  277):   at dalvik.system.NativeStart.run(Native Method)
I/ActivityManager(  277): START {act=android.nfc.action.NDEF_DISCOVERED typ=application/vnd.wfa.wsc pkg=at.nfc.wifi (has extras)} from pid 3938
W/ActivityManager(  277): Duplicate finish request for ActivityRecord{41163a90 com.android.nfc/.NfcRootActivity}
D/power   (  277): Already locked performance.
I/Intent  (  277): @test_code: getHtcIntentFlag: 0 obj: 1094379848
W/CpuWake (  277): >>acquireCpuPerfWakeLock!
W/CpuWake (  277): <<acquireCpuPerfWakeLock!

问题可能是版本4.1.1与4.0.3 - 我不知道: 事实是: 只有Ndef适用于三星,如果我添加

1 个答案:

答案 0 :(得分:2)

bug in Android使AAR基本上毫无价值。根据电话状态,当NFC服务处理标签时,AAR或意图过滤器优先。如果AAR获胜,则无法获得标签。

您可以正确处理此问题的唯一方法是删除AAR,将其替换为您控制的服务器的网址,该网址可以重定向到Google Play上的应用页面。