6
傳輸.apk文件我已經轉換我的apk文件成字節陣列,並使用web服務如下需要使用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();
}
我在我的機器人應用消耗使用KSOAP協議網絡服務爲字節發送陣列如下給出
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();
}
問題是,我沒有得到確切的apk文件後,將字節數組[]返回到文件。
請問任何人請查看代碼,請告訴我有沒有在這個錯誤。
我需要將轉換後的byte [] apk文件轉換回SD卡中的.apk文件進行安裝。
我已經嘗試過了......但問題是,我現在用點網webservice.So的時候纔來的Java部分不能解析到回APK轉換文件文件。如果它是Java到Java通信,它將是可能的。 –