gpt4 book ai didi

android - 需要使用 webservice 传输 .apk 文件

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:40:27 24 4
gpt4 key购买 nike

我已经将我的 apk 文件转换成字节数组并使用 webservice 发送它,如下所示

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

我在我的 android 应用程序中使用 ksoap 协议(protocol)作为数组字节消费了 web 服务,如下所示

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文件取回sdcard中的.apk文件进行安装。

最佳答案

response.toString() 可能不是您的 APK 的字符串表示形式。

尝试以下操作:

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

关于android - 需要使用 webservice 传输 .apk 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8135376/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com