更新问题!

时间:2010-04-19 16:41:54

标签: android

这是我面临的问题:尝试进行自己的应用程序更新我从SD卡上的Web服务器下载更新apk,然后我使用下载路径启动Package Installer(旧应用程序正在运行时) 。在软件包安装程序启动并且用户同意安装应用程序后,到目前为止,我收到以下消息“MyApp无法安装在此手机上”,然后在logcat中打印以下消息: “获取资源号0x00000000的值时没有包标识符”。我找不到这种行为的原因,所以如果有什么我想念的东西请指出我!

try
 {
   BufferedInputStream getit = new BufferedInputStream(new URL("http://mywebserver:8080/myapk.apk").openStream());
   FileOutputStream saveit = new FileOutputStream(path);
   BufferedOutputStream bout = new BufferedOutputStream(saveit,1024);
   byte data[] = new byte[1024];
   int readed = getit.read(data,0,1024);
   while(readed != -1)
    {
        bout.write(data,0,readed);
        readed = getit.read(data,0,1024);
    }
    bout.close();
    getit.close();
    saveit.close();
}
catch(Exception e)
{
   e.printStackTrace
}

1 个答案:

答案 0 :(得分:0)

尝试使用“package installer”版本的以下示例内容。 该示例将不解释如何从服务器下载文件。它将假设它已经是一个字节数组。

byte[] data = dataReadFromServer;

FileOutputStream outStream = openFileOutput("somename.apk", Context.MODE_WORLD_READABLE);
outStream.write(data);
Intent intent = new Intent();
String absolutePath = "file://" + getFilesDir().getAbsolutePath() + "/" +
"somename.apk"; 
intent.setAction(android.content.Intent.ACTION_VIEW); 
intent.setDataAndType(Uri.parse(absolutePath), "application/vnd.android.package-archive"); 
startActivity(intent);
相关问题