1
當我嘗試使用以下代碼下載文件並運行apk文件時,它總是導致「解析錯誤」。我無能爲力。任何幫助表示讚賞。安卓從互聯網下載apk文件導致解析錯誤
try
{
URL url = new URL("http://10.0.0.1/test.apk");
URLConnection conexion = url.openConnection();
conexion.connect();
int lenghtOfFile = conexion.getContentLength();
InputStream is=url.openStream();
FileOutputStream fos=new FileOutputStream("/flash/test.apk");
byte data[]=new byte[1024];
int count=0;
long total=0;
int progress=0;
while ((count=is.read(data)) != -1)
{
total += count;
int progress_temp = (int)total*100/lenghtOfFile;
if(progress_temp%10 == 0 && progress != progress_temp){
progress = progress_temp;
Log.v("APK Download", "total = "+progress);
// Log.v
}
fos.write(data, 0, count);
}
is.close();
fos.close();
Log.v("APK Download", "Download Done");
}catch (Exception e){}
請顯示堆棧跟蹤的確切文本,並指出它指的是哪一行。 – 2010-12-01 21:49:36