title: Read Large data from Smart card With Error tag was lost
body: <p>I want to Read/write large data in smart card via nfc in Android App.
  according link <a href="https://stackoverflow.com/questions/40366099/send-more-than-261-bytes-to-java-card-with-android-nfc/40375229?noredirect=1#comment68024797_40375229">Send more than 261 bytes to Java Card with Android NFC</a>
   I can write  large apdu block by block. </p>
  
  <p>but when I want to read large data I have problem:
  I wrote this code for read large data in android app</p>
  
  <pre><code>  public  byte[] ReadCertificate(int keyindex)
  {
      byte ReadCertAPDU[]=new byte[5];
      byte Read_Cert_CLA = AppletCLA;
      byte Read_Cert_INS = (byte)0x26;
      byte Read_Cert_P1 = (byte)0x00;
      byte Read_Cert_P2 = (byte)keyindex;
      byte Read_Cert_LE = (byte)0xFF;
  
      byte[] cert=new byte[2000];
      ReadCertAPDU[0] = Read_Cert_CLA;
      ReadCertAPDU[1] = Read_Cert_INS;
      ReadCertAPDU[2] = Read_Cert_P1;
      ReadCertAPDU[3] = Read_Cert_P2;
      ReadCertAPDU[4] = Read_Cert_LE;
  
      try {
  
          byte[] response = transceives(ReadCertAPDU);
          if(response==null)
              return null;
  
          else {
              if (response[0] == (byte) 0x61)
                  response = GetResult2(LogStep, response);
              return response;
          }
  
      }
      catch (Exception e)
      {
          Log.e( LogStep,e.getMessage()+" IOException on Sent Command: ");
      }
      return  null;
  
  }
  </code></pre>
  
  <p>I get Error Tag was lost in exception in transceives() method.when I test it in pyapdu tool I don't have problem. and I get data + 61FF that I continue sending 00c00000ff and I get result. but in android app I have problem
  in my applet I have method :</p>
  
  <pre><code>private void ReadCertificate(APDU apdu)
   {
       byte[] buffer=apdu.getBuffer();
       byte P2=buffer[ISO7816.OFFSET_P2];
  
       Util.arrayCopyNonAtomic(((byte[])CertificateArray[P2]),(short)0,Certificate, (short) 0,(short)Certificate.length);
  
  
      short toSend = (short) Certificate.length; 
  
      try {
          apdu.setOutgoing();
          apdu.setOutgoingLength(toSend);
          byte counter = 0;
          short senddate;
          while (toSend &gt; 0) {
              if(toSend&gt;255)
                  senddate=(short)255;
              else
                  senddate=toSend;
              apdu.sendBytesLong(Certificate, (short) (255 * counter), senddate);
  
              toSend = (short) (toSend - senddate);
              counter = (byte) (counter + 1);
          }
      } 
    catch (Exception e) {
  
      }
   }
  </code></pre>