我從服務器下載在Android的應用程序,並把它保存在內部存儲器:安卓:錯誤解析包
URLConnection connection = url.openConnection();
connection.connect();
// download the file
InputStream input = new BufferedInputStream(url.openStream());
OutputStream output = new FileOutputStream(getFilesDir() + "/filename");
byte data[] = new byte[1024];
while ((count = input.read(data)) != -1) {
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();
當下載完成後,會出現一個通知。點擊通知後,應該安裝應用程序。
Intent i = new Intent(Intent.ACTION_VIEW);
i.setDataAndType(Uri.fromFile(new File(getFilesDir()+ "/filename")),"application/vnd.android.package-archive");
PendingIntent act = PendingIntent.getActivity(MainActivity._activity,0, i, 0);
notification.setLatestEventInfo("TEXT", "TEXT, act);
但是當我點擊該通知,一個對話框,說:出現錯誤解析包。爲什麼?
您是否在logcat中找到附加信息? – yoshi 2012-07-18 10:41:34
yes:解析清單時出現分析錯誤。停止安裝 – 2012-07-18 11:59:23
我遇到了同樣的問題...我打開FileOutputStream,寫入,刷新,打開目標並彈開 – SparK 2014-04-22 15:08:01