我遇到了Mifare DESFire 卡的问题。
我使用transceive()
方法发送apdu以选择PICC应用程序,应用程序流程为:
1)发现的技术
2)使用
创建MifareDESFire对象intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
3)被叫connect();
4)使用transceive();
发送选择PICC app apdu命令 5)发送时收到"android.nfc.TagLostException: Tag was lost."
APDU。我用'****'
指定误差高于误差的线
这是我的onNewIntent
事件:
public void onNewIntent(Intent intent)
{
String action = intent.getAction();
if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(action)
|| NfcAdapter.ACTION_TECH_DISCOVERED.equals(action)
|| NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) {
Toast.makeText(this, "discovered", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Falied", Toast.LENGTH_SHORT).show();
}
byte cmdSelect_PICCapp=(byte) 0x5A ; //select my app
byte[] PICCAPPID = new byte[]{(byte)0x00 ,(byte)0x00 , (byte)0x00};
byte[] tagResponse_cmdSelect_PICC_app = new byte[]{(byte)0x12 ,(byte)0x12};
Tag desfire = (Tag) intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
isodep = IsoDep.get(desfire);
try
{
isodep.connect();
} catch (IOException e)
{
e.printStackTrace();
}
**** tagResponse_cmdSelect_PICC_app = isodep.transceive(Utils.wrapMessage(cmdSelect_PICCapp, PICCAPPID));
Log.d("picc app selected", "111 "+Utils.bytesToHex(tagResponse_cmdSelect_PICC_app));
try
{
isodep.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
和 Class Utils在这里:
public class Utils {
final protected static char[] hexArray = "0123456789ABCDEF".toCharArray();
public static byte[] wrapMessage (byte command, byte[] parameters) throws Exception {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
stream.write((byte) 0x90);
stream.write(command);
stream.write((byte) 0x00);
stream.write((byte) 0x00);
if (parameters != null) {
stream.write((byte) parameters.length);
stream.write(parameters);
}
stream.write((byte) 0x00);
byte[] b = stream.toByteArray();
return b;
}
//**************************************
public static String bytesToHex(byte[] bytes)
{
char[] hexChars = new char[bytes.length * 2];
for ( int j = 0; j < bytes.length; j++ )
{
int v = bytes[j] & 0xFF;
hexChars[j * 2] = hexArray[v >>> 4];
hexChars[j * 2 + 1] = hexArray[v & 0x0F];
}
return new String(hexChars);
}
}//end class Utils
感谢任何人都可以帮助我。
谢谢。