Samsung Nexus S vs HTC - NFC Intent Filter + AAR
Asked Answered
B

1

2

I save the AAR on my NFC-Tag. If I scan the TAG with the Nexus S (Android 4.1.1), i get the NfcAdapter.ACTION_NDEF_DISCOVERED and the NFCReaderActivity directly starts.

If I do the same with the HTC X (Android 4.0.3), the application starts but I just get the android.intent.action.MAIN and so the NFCReaderActivity doesn't show up and the Tag isn't scanned.

This works on Samsung Nexus S but not on 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>   

This are my activities and filters.

Someone an idea?


Edit:

This works on HTC but not on 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>   

Here I got the following Exception @ HTC - maybe this is the Problem i don'tknow: Stack:

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!

Maybe the Problem is the version 4.1.1 vs 4.0.3 - I don't know: Fact is: Only Ndef works on Samsung, If i add the

Bisectrix answered 2/10, 2012 at 18:20 Comment(8)
Obvious question: is NFC enabled in Settings on the HTC X?Lipson
yes is is enabled. somehow the htc doesn react on the ndef-dicovered filter without the mimetype data tag... if I add the <data mimeType ... tag, the activity starts - but then I have a problem with the samsung nexus s. why is the general version (without the data tag) not matching @ htc?Bisectrix
in Logcat I can see that htc shows me this error: startLaunchActivity get appname failed java.lang.NullPointerException at com.android.server.am.ActivityStack.startLaunchActivity(ActivityStack.java:4831) ...Bisectrix
Post full stack trace. No idea why it doesn't work on HTC, try mimeType="/".Lipson
You can see it above under the Edit: Only Ndef works on Samsung, If i add the <data mimetype tag - It works on HTC but not on Samsung. The Problem is because the first Record on the Tag is a HandoverSelect Record. The second is the application/vnd.wfa.wsc Record.It seems that Samsung Nexus S just scannes the first Record for the Type- so it doesn't match the data mimetype but It works with the general option (without the data tag). HTC seems to scan also the second Record and there it matches the application/vn..Record and starts the ReaderActivity. But the HTC doesn't match the general one.Bisectrix
Seems like a bug/limitation of the particular version. Doesn't a wildcard mime type work ('/')? If you can get it to recognize this, you can process that data yourself afterwards by reading all records.Lipson
The wildcard would work on HTC, but there the explicit mimetype also works. On Samsung it both doesn't work because the Samsung seems to scan only the first record for the mimetype and the first record is the HandoverSelect of Type TNF_WELL_KNOWN (The RTD type name format is specified in NFCForum-TS-RTD_1.0.) and this is mapped on Action_TAG_DISCOVERED (developer.android.com/guide/topics/connectivity/nfc/nfc.html) but this mapping doesn't work for me on both phones ^^. It would be OK if just the android.nfc.action.NDEF_DISCOVERED would work on HTC without the additional filter... ThanksBisectrix
In that case, I can't think of anything but registering for ACTION_TAG_DISCOVERED and checking manually if it has NDEF on it or not. Might be awkward if you have other NFC apps though.Lipson
A
2

There is a bug in Android that makes AAR basically worthless. Depending on the phone state, either the AAR or the intent filter is taking precedence when the NFC service is handling the tag. If the AAR wins, you have no means of obtaining the tag.

The only way you can handle this properly is to remove the AAR, replacing it with a URL to a server you control, that can redirect to your app page on Google Play.

Allhallowmas answered 10/12, 2012 at 13:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.