私は現在、NFCスマートフォン用のAndroidアプリケーション(JAVA)を開発しています。Nfcaタグと通信しようとしていますが、TagLostException
を介して送信したコマンドに関係なく取得し続けますtransceive(byte[])
。タグはデバイスに適切に接続されています。
重要なコードは次のとおりです。
public void onNewIntent(Intent intent) {
setIntent(intent);
tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); // get the tag object for the discovered tag
nfca = NfcA.get(tag); // try and get the instance for this tag
if(nfca == null) {
Alert("tag","the tag is not NfcA");
} else {
new Thread(new Runnable() {
@Override
public void run() {
handler.sendEmptyMessage(1); //this will call handleMessage function and handle all error
}
}).start();
}
}
final Handler handler = new Handler() {
//handles the connection with the tag
@Override
public void handleMessage(final Message msgs) {
// try to connect to the NfcA tag
try {
nfca.connect();
} catch(IOException e) {
Alert("nfca.connect","cannot open connection ><");
}
Toast.makeText(NfcaActivity.this, "tag connected", Toast.LENGTH_LONG).show();
}
};
try {
//nfca.setTimeout(3000);
pageBuffer = nfca.transceive(command);
} catch(IOException e) {
Alert("pageBuffer","cannot perform transceive "+ e.toString());
} catch(Exception e) {
Alert("exception!", e.toString());
}
私は次のコマンドで試しています:{00 CA 42 08 00}
または{00 A4 00 00 02 3F00}
、同じ結果が得られます。
これらのコマンドは、PCでスマートカードリーダーとソフトウェアを使用しているときに機能します。スマートカードは空ではありません。