我在阅读 NFC 标签时遇到了 2 个问题。
首先是每次收到标签时都会创建标签读取活动。
第二个问题是活动在全屏窗口中打开,而不是在选项卡主机活动下,但第一个问题是最糟糕的。
我该怎么做(AndroidManifest.xml):
<activity
android:name="readingActivity" >
<intent-filter>
<action android:name="android.nfc.action.TAG_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
和阅读Activity.cs:
@Override
public void onCreate(Bundle savedInstanceState) {
Log.d("W", "onCreate");
super.onCreate(savedInstanceState);
setContentView(R.layout.readingActivity);
}
@Override
public void onResume() {
super.onResume();
Log.d("W", "onResume");
PendingIntent intent = PendingIntent.getActivity(this, 0, getIntent(), 0);
NfcAdapter.getDefaultAdapter(this).enableForegroundDispatch(this, intent,
null, null);
}
@Override
protected void onPause() {
super.onPause();
if(NfcAdapter.getDefaultAdapter(this) != null)
NfcAdapter.getDefaultAdapter(this).disableForegroundDispatch(this);
}
日志:
02-28 18:22:19.949: D/W(4513): onCreate
02-28 18:22:19.949: D/W(4513): onResume
02-28 18:22:21.078: D/W(4513): onCreate
02-28 18:22:21.082: D/W(4513): onResume