2011-11-15 16 views
6

He convertido mi archivo apk en una matriz de bytes y enviarlo mediante servicio web de la siguiente maneranecesidad de transferir el archivo APK utilizando servicio web

[WebMethod] 
    public byte[] GetApkFile(string deviceID) 
    { 
     try 
     { 
      string path = ServiceHelper.GetTempFilePath(); 
      string fileName = path + "\\VersionUpdate.apk"; 
      FileStream fileStream = File.OpenRead(fileName); 
      return ConvertStreamToByteBuffer(fileStream);   
     } 
     catch (Exception ex) 
     { 
      throw ex; 

     } 

    } 

     public byte[] ConvertStreamToByteBuffer(System.IO.Stream theStream) 
    { 
     int b1; 
     System.IO.MemoryStream tempStream = new System.IO.MemoryStream(); 
     while ((b1 = theStream.ReadByte()) != -1) 
     { 
      tempStream.WriteByte(((byte)b1)); 
     } 
     return tempStream.ToArray(); 
    } 

he consumido el servicio web utilizando el protocolo ksoap en mi aplicación Android como bytes de matriz como se indica a continuación

public void DownloadApkFile(String serverIPAddress, 
     String deviceId) { 

    String SOAP_ACTION = "http://VisionEPODWebService/GetApkFile"; 
    String OPERATION_NAME = "GetApkFile"; 
    String WSDL_TARGET_NAMESPACE = "http://VisionEPODWebService/"; 
    String SOAP_ADDRESS = ""; 
    SOAP_ADDRESS = "http://" + serverIPAddress 
      + "/VisionEPODWebService/SystemData.asmx"; 
    SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE, 
      OPERATION_NAME); 
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
      SoapEnvelope.VER10); 
    new MarshalBase64().register(envelope); 
    envelope.encodingStyle = SoapEnvelope.ENC; 
    request.addProperty("deviceID", deviceId); 
    envelope.dotNet = true; 
    envelope.setOutputSoapObject(request); 
    HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS); 
    try { 
     httpTransport.call(SOAP_ACTION, envelope); 
     Object response = envelope.getResponse(); 
     byte[] b=response.toString().getBytes(); 

     String fileName = "/sdcard/" + "VersionUpdate" + ".apk"; 

     FileOutputStream fileOuputStream = 
        new FileOutputStream(fileName); 
     fileOuputStream.write(b); 
     fileOuputStream.close();   

    } 

    catch (Exception exception) { 
     exception.toString();   
    } 

el problema es que no estoy recibiendo el archivo exacto apk después de convertir la matriz de bytes [] de nuevo a archivo.

¿Alguien puede revisar el código y por favor dígame si hay algún error en esto.

Mi necesidad de obtener el archivo convertido byte [] apk de nuevo en el archivo .apk en la tarjeta sd para la instalación.

Respuesta

1

response.toString() es probable que no sea una representación de cadena de su APK.

intente lo siguiente:

SoapObject result = (SoapObject)envelope.bodyIn; 
byte[] b=result.toString().getBytes(); 
+0

Lo he probado ... pero el problema es que me estoy convirtiendo el archivo con puntos webservice.So neta cuando se trata de parte de java que no puede analizar hacia atrás para apk archivo. Si es Java a Java, la comunicación será posible. –

Cuestiones relacionadas