Necesidad de transferir el archivo .apk mediante webservice
He convertido mi archivo apk en array de bytes y lo envío usando webservice como sigue
[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
- Tutorial de servicio web de Android
- Android - ¿Cómo manejar Webservice en XML?
- Poner byte en JSON en android
- Android Obtener archivo pdf como resultado de httppost
- Conexión a host local: 3000 rechazado en dispositivo Android
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 consiguiendo el archivo apk exacto después de convertir la matriz del byte [] de nuevo al archivo.
¿Alguien puede revisar el código y por favor dígame que hay algún error en esto.
Mi necesidad de obtener el archivo convertido byte [] apk de nuevo al archivo .apk en el sdcard para la instalación.
- No se pueden serializar las fechas con ksoap2
- Desarrollador web visual Servicio web en depuración HTTP / 1.1 400 Solicitud incorrecta
- En caché JSON de webservice en android - patrón?
- Error: NullPointerAccess: La variable "" sólo puede ser null en esta ubicación
- JSON Cadena devuelta desde el servicio web SOAP que no contiene registros para la tabla
- Android: ¿Es una buena idea almacenar Token de autenticación en las preferencias compartidas?
- ¿Cómo puedo recibir notificaciones múltiples usando GCM sin reemplazar la precedente?
- Cómo llamar a un json webservice a través de android
response.toString()
es probable que no sea una representación de cadena de su APK.
Pruebe lo siguiente:
SoapObject result = (SoapObject)envelope.bodyIn; byte[] b=result.toString().getBytes();
- Lectura Más de 20 byte de dispositivo BLE remoto falló en Lolipop
- Cómo configurar la sombra del botón de Android en lugar de configurar la sombra del texto