exception - How solve "android.nfc.TagLostException: Tag was lost." ?(Select PICC app) -


i facing issue mifare desfire card.

i usetransceive() method send apdu selection picc app, flow of application is:

1) tech discovered

2) create mifaredesfire object using

intent.getparcelableextra(nfcadapter.extra_tag); 

3) called connect();

4) send select picc app apdu command using transceive();

5) received "android.nfc.taglostexception: tag lost." when send apdu. specify line maked above error '****' here onnewintent event:

    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 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();             }    } 

and class utils here:

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];         ( 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 

appreciate can me.

thank you.


Comments