私の Android nfc アプリは、スマート カードの読み取りを完了すると、同じ NFC タグ情報で再び提示され、オペレーティング システムによって再度起動されます。実際、電話を動かさないと、永久ループに入ります。読み取られるデータの量には 1 ~ 2 秒かかるため、最後にもう一度開始します。(これは、Galaxy S2 Gingerbread と S3 on ICS ではかなり一般的です)
NFC ソース (スマート カード) が変更されておらず、携帯電話から離れていない場合、どのように繰り返すのを止めることができますか?
私のアクティビティには、次のインテント フィルタがあります。
<intent-filter >
<action android:name="android.nfc.action.TECH_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.nfc.action.TAG_DISCOVERED" />
</intent-filter>
<meta-data
android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="@xml/filter_nfc" />
の技術リストで
<tech-list>
<tech>android.nfc.tech.IsoDep</tech>
</tech-list>
ソースコード:
@Override
protected void onCreate(Bundle savedInstanceState) {
resolveIntent(getIntent());
}
@Override
public void onNewIntent(Intent intent) {
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
private void resolveIntent(Intent intent) {
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
final String action = intent.getAction();
if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(action)
|| NfcAdapter.ACTION_TAG_DISCOVERED.equals(action)) {
....work
handled = true;
}
if (!handled) {
Log.e(tag, "Unknown intent " + intent);
finish();
return;
}
}