此代码在从webserver下载后运行apkfile。
但是..
当apkfile运行时,它会打印此消息。
- 稀疏错误
“解析包时出现问题。”
当我在复制到设备后运行apkfile时,它没有打印消息。
我该如何解决这个问题?
p.s)启动方法是skinDownload(filename)。
String File_Name = "";
String File_extend = "";
String fileURL = "http://URL/";
String Save_Path = "/data/data/kr.appsol.util.calc.formcalc/themes";
DownloadThread dThread;
ProgressDialog downDialog = null;
private void skinDownload(String filename){
File_Name = filename + ".apk";
File_extend = "apk";
File dir = new File(Save_Path);
if (!dir.exists()) {
dir.mkdir();
}
if (new File(Save_Path + "/" + File_Name).exists() == false) {
downDialog = ProgressDialog.show(Activity_SkinList.this, "", getString(R.string.setting_skin_downloading));
downDialog.show();
dThread = new DownloadThread(fileURL + "/" + File_Name,
Save_Path + "/" + File_Name);
dThread.start();
} else {
showDownloadFile();
}
}
class DownloadThread extends Thread {
String ServerUrl;
String LocalPath;
DownloadThread(String serverPath, String localPath) {
ServerUrl = serverPath;
LocalPath = localPath;
}
@Override
public void run() {
URL imgurl;
int Read;
try {
imgurl = new URL(ServerUrl);
HttpURLConnection conn = (HttpURLConnection) imgurl
.openConnection();
int len = conn.getContentLength();
byte[] tmpByte = new byte[len];
InputStream is = conn.getInputStream();
File file = new File(LocalPath);
FileOutputStream fos = new FileOutputStream(file);
for (;;) {
Read = is.read(tmpByte);
if (Read <= 0) {
break;
}
fos.write(tmpByte, 0, Read);
}
is.close();
fos.close();
conn.disconnect();
} catch (MalformedURLException e) {
Log.e("ERROR1", e.getMessage());
} catch (IOException e) {
Log.e("ERROR2", e.getMessage());
e.printStackTrace();
}
mAfterDown.sendEmptyMessage(0);
}
}
Handler mAfterDown = new Handler() {
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
downDialog.dismiss();
// run
showDownloadFile();
}
};
private void showDownloadFile() {
File apkFile = new File(Save_Path + "/" + File_Name);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive");
startActivity(intent);
}
答案 0 :(得分:0)
您可能需要在关闭之前刷新流:
fos.flush();
fos.close();