所以需加上下列程式碼
/*此頁面關閉NFC感應*/
@Override
protected void onResume() {
super.onResume();
// creating pending intent:
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
new Intent(this, getClass())
.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
// enabling foreground dispatch for getting intent from NFC event:
NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
try {
// nfcAdapter.enableForegroundDispatch(this, pendingIntent,
// new IntentFilter[] { filter }, this.techList); 開啟nfc
nfcAdapter.enableForegroundDispatch(this, pendingIntent,
new IntentFilter[] {}, null); // 關閉nfc IntentFilter[] {}內設為空值, techList改為null空值
} catch (NullPointerException e) {
}
}
參考資料: http://stackoverflow.com/questions/9748513/reading-nfc-tags-only-from-a-particuar-activity

沒有留言 :
張貼留言