【发布时间】:2015-01-20 13:06:32
【问题描述】:
我想为我的应用程序模拟触摸事件。我的清单就像
<activity
android:name=".activity.TagActivity_"
android:label="@string/app_name"
android:launchMode="singleTask"
android:noHistory="true"
android:permission="android.permission.NFC"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED" />
</intent-filter>
<meta-data
android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="@xml/nfc_tech_filter" />
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="ext"
android:pathPrefix="/abc:d"
android:scheme="vnd.android.nfc" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
问题 (1):我想从其他应用程序调用我的应用程序。我怎么做?我当前的代码是这样的:
try {
final Intent intent = new Intent(NfcAdapter.ACTION_NDEF_DISCOVERED);
NdefMessage ndefMessage = buildNdefMessage(getTagData());
intent.putExtra(NfcAdapter.EXTRA_NDEF_MESSAGES, new NdefMessage[] {ndefMessage});
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
但这并不是在调用我的应用程序。可能是因为数据类型和路径前缀不匹配。如何在开始活动时传递这个?
问题(2):出于临时目的,我添加了
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
使其工作,并调用我的应用程序。但是在阅读标签时,我会检查标签类型,因为我没有传递任何标签类型,所以我的应用程序崩溃了。那么如何创建标签实例呢?没有为此的构造函数。我的意思是我不能做Ndef ndef = new Ndef();。而且我基本上没有标签,所以我不能做Ndef ndef = Ndef.get(tag);。
【问题讨论】:
标签: android android-intent nfc intentfilter ndef