Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何解决;android.nfc.TagLostException:标记丢失?(选择PICC应用程序)_Android_Exception_Nfc_Mifare_Apdu - Fatal编程技术网

如何解决;android.nfc.TagLostException:标记丢失?(选择PICC应用程序)

如何解决;android.nfc.TagLostException:标记丢失?(选择PICC应用程序),android,exception,nfc,mifare,apdu,Android,Exception,Nfc,Mifare,Apdu,我面临Mifare DESFire卡的问题 我使用transceive()方法发送apdu选择PICC app,应用流程如下: 1) 科技发现 2) 使用创建MifareDESFire对象 intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); 3) 调用connect() 4) 使用收发器()发送选择PICC app apdu命令 5) 收到一个“android.nfc.TagLostException:标记丢失。”当我发送 阿普杜。我通过一个'**

我面临Mifare DESFire卡的问题

我使用
transceive()
方法发送apdu选择PICC app,应用流程如下:

1) 科技发现

2) 使用创建MifareDESFire对象

intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
3) 调用
connect()

4) 使用收发器()发送选择PICC app apdu命令

5) 收到一个
“android.nfc.TagLostException:标记丢失。”
当我发送 阿普杜。我通过一个
'***'
这是我的
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();
            }
   }
及 类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
公共类Utils{
最终受保护的静态字符[]hexArray=“0123456789ABCDEF”.toCharArray();
公共静态字节[]wrapMessage(字节命令,字节[]参数)引发异常{
ByteArrayOutputStream=新建ByteArrayOutputStream();
stream.write((字节)0x90);
stream.write(命令);
stream.write((字节)0x00);
stream.write((字节)0x00);
if(参数!=null){
stream.write((字节)参数.length);
stream.write(参数);
}
stream.write((字节)0x00);
字节[]b=stream.toByteArray();
返回b;
}
//**************************************
公共静态字符串bytesToHex(字节[]字节)
{
char[]hexChars=新字符[bytes.length*2];
对于(int j=0;j>>4];
hexChars[j*2+1]=hexArray[v&0x0F];
}
返回新字符串(hexChars);
}
}//端类UTIL
谢谢,任何人都可以帮助我

谢谢。

我猜当您的卡芯片损坏时会出现“标签丢失错误”。我能在这里找到我要承诺的答案吗。