2010-04-19 109 views
0

這就是我面臨的問題:試圖做我自己的應用程序更新我從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 
} 

回答

0

嘗試使用下面的「軟件包安裝程序」版本的示例代碼。 該示例不會解釋如何從服務器下載文件。它會假定它已經在一個字節數組中。

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); 
+0

其實這就是我的代碼看起來很像,我已經下載的apk文件,然後發送一個意圖啓動包安裝程序。如果我把另一個應用程序的apk,我可以安裝它,但我不能這樣做,如果我試圖安裝的apk是當前應用程序的更新版本(我在AndroidManifest.xml中增加versionCode標記) – 2010-04-19 19:28:07

+0

你是否使用這個確切操作:android.content.Intent.ACTION_VIEW? – FiDo 2010-04-19 21:10:09

+0

是的,但這不是問題。當我發現我正在嘗試使用debugable = true set更新應用程序時,更新apk已經簽名! – 2010-04-20 16:05:57