Android NFC: can we use intent filter with mime type? (android 2.3.3)

送分小仙女□ 提交于 2019-12-11 03:27:31

问题


I'm trying to start an activity when "tapping" a nfc tag containing a specific mime type. I made a tag with the mime type "text/plain", and added this in the manifest:

<intent-filter>
  <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
  <data android:mimeType="text/plain" />
</intent-filter>

If I tap a nfc tag, nothing happen, even if the intent seems right, here is what I see in logs:

03-13 23:36:56.871: INFO/ActivityManager(114): Starting: Intent { act=android.nfc.action.NDEF_DISCOVERED typ=text/plain flg=0x10000000 (has extras) } from pid 192

If I replace the "mime intent-filter" by this one:

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

the activity is started when a tap the nfc tag. I'm using a Nexus S on 2.3.3.

Any clues?

BR, Patrick


回答1:


I had a similar problem and could solve it by adding a category element:

<intent-filter>
  <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
  <data android:mimeType="text/plain"/>

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

</intent-filter>

-Oliver



来源:https://stackoverflow.com/questions/5293056/android-nfc-can-we-use-intent-filter-with-mime-type-android-2-3-3

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!