2012-07-18 118 views
1

我從服務器下載在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); 

但是當我點擊該通知,一個對話框,說:出現錯誤解析包。爲什麼?

+0

您是否在logcat中找到附加信息? – yoshi 2012-07-18 10:41:34

+0

yes:解析清單時出現分析錯誤。停止安裝 – 2012-07-18 11:59:23

+0

我遇到了同樣的問題...我打開FileOutputStream,寫入,刷新,打開目標並彈開 – SparK 2014-04-22 15:08:01

回答

1

具有相同包名的另一個應用程序可能已經安裝在設備中。所以你得到的錯誤。

+0

不,我確信沒有其他應用程序具有相同的軟件包名稱。 – 2012-07-18 10:07:08

+0

我認爲你下載的文件已損壞(或)來自u'r服務器的文件已損壞。你檢查過嗎? – Hein 2012-07-18 10:36:54

+0

當我試圖從瀏覽器下載應用程序時,它完美地工作。 – 2012-07-18 11:17:13