私は異なるNFCタグを読み書きするためのアンドロイドアプリケーションを開発しています。特定のタグ、iCODE SLI X、iCODE SLI Sに問題が発生しました。タグに関する情報を書き込んだ後、他のアクションを実行できません。NFCが正常に機能しなくなったように見えます。それは実際にタグを読むでしょう。 MIFARE Classic 1Kのような別のタグタイプを使用すると、これは起こりません。 Androidのバージョンは6.0です。NFCは、iCODEタグ、Android 6.0での書き込み後に動作を停止します。
一方、Android 6.1または7.0(まったく同じコード)の別のデバイスでアプリケーションを試すと、iCODE SLI XとiCODE SLISは正常に動作しますが、MIFARE Classic 1Kでは正常に動作しません。
さまざまなコードサンプルを試すだけでなく、これらのデバイスで2つのアプリケーションも試しました。 「NFCツール」では、アプリケーションで発生しているのとまったく同じ問題が発生します。 NXPの「TagWriter」は、すべてのタイプのタグで魅力的に機能する唯一のアプリケーションです。ここで
は、私は、タグに情報を書き込むために使用しているコードです:
@Override
protected void onNewIntent(Intent intent) {
if (mNfcAdapter.ACTION_TAG_DISCOVERED.equals(intent.getAction())) {
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
if (tag != null) {
try {
Ndef ndef = Ndef.get(tag);
NdefRecord text1 = new NdefRecord(NdefRecord.TNF_WELL_KNOWN,
youstring1.getBytes(Charset.forName("US-ASCII")),
null,
youstring1.getBytes());
NdefRecord text2 = new NdefRecord(NdefRecord.TNF_WELL_KNOWN,
youstring2.getBytes(Charset.forName("US-ASCII")),
null,
youstring2.getBytes());
NdefRecord[] records = {text1, text2};
NdefMessage message = new NdefMessage(records);
if (ndef != null) {
NdefMessage ndefMesg = ndef.getCachedNdefMessage();
if (ndefMesg != null) {
ndef.connect();
ndef.writeNdefMessage(message);
ndef.close();
}
} else {
NdefFormatable ndefFormatable = NdefFormatable.get(tag);
if (ndefFormatable != null) {
// initialize tag with new NDEF message
try {
ndefFormatable.connect();
ndefFormatable.format(message);
ndefFormatable.close();
} finally {
try {
//ndefFormatable.close();
} catch (Exception e) {
}
}
}
}
}catch (FormatException |IOException ue){}
}
}
}
私はおそらく間違ってやっているのか理解できません...