安卓:错误解析包
我从服务器下载在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);
但是当我点击该通知,一个对话框,说:出现错误解析包。为什么?
具有相同包名的另一个应用程序可能已经安装在设备中。所以你得到的错误。
不,我确信没有其他应用程序具有相同的软件包名称。 – 2012-07-18 10:07:08
我认为你下载的文件已损坏(或)来自u'r服务器的文件已损坏。你检查过吗? – Hein 2012-07-18 10:36:54
当我试图从浏览器下载应用程序时,它完美地工作。 – 2012-07-18 11:17:13
您是否在logcat中找到附加信息? – yoshi 2012-07-18 10:41:34
yes:解析清单时出现分析错误。停止安装 – 2012-07-18 11:59:23
我遇到了同样的问题...我打开FileOutputStream,写入,刷新,打开目标并弹开 – SparK 2014-04-22 15:08:01