1
我從服務器下載的Android應用程序,並用它保存到我的應用程序的內部空間應用:安卓:不能安裝保存到內部存儲器
URL url = new URL(Urls[0]);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
File outputFile = new File(getFilesDir(), "Apps");
outputFile.mkdirs();
File file = makeFilename(outputFile, _appName + ".apk");
file.createNewFile();
file.setExecutable(true);
file.setReadable(true, false);
file.setWritable(true, false);
FileOutputStream fout = new FileOutputStream(zipFile);
InputStream in = conn.getInputStream();
byte[] buffer = new byte[1024];
int length = 0;
while ((length = in.read(buffer)) > 0) {
fout.write(buffer, 0, length);
}
fout.close();
in.close();
outputFile.setExecutable(true, false);
outputFile.setReadable(true, false);
outputFile.setWritable(true, false);
private File makeFilename(File base, String name) {
if (name.indexOf(File.separatorChar) < 0) {
return new File(base, name);
}
throw new IllegalArgumentException("File " + name
+ " contains a path separator");
}
當下載完成後,將出現一個通知。當我點擊這個通知時,應該安裝該應用程序。但實際上,當我點擊通知時,出現「分析包錯誤」。我做錯了什麼?
Intent i = new Intent(Intent.ACTION_VIEW);
i.setDataAndType(Uri.fromFile(new File(getFilesDir()+ "/Apps/_appName.apk")),"application/vnd.android.package-archive");
PendingIntent act = PendingIntent.getActivity(MainActivity._activity,0, i, 0);
notification.setLatestEventInfo("TEXT", "TEXT, act);
你可以包含logcat中顯示的內容嗎? – vArDo 2012-07-18 12:40:58
解析清單時出現分析錯誤。停止安裝 – 2012-07-18 12:48:49