2011-08-09 138 views
1

期間,我需要能夠發出更新,而無需通過Android商店去一個測試階段。我發現了一些關於這個的帖子,但是他們都沒有爲我工作。該文件本身下載的罰款,但兩個替代方案我得到一個錯誤:定製的Android應用程序安裝

08-09 16:31:20.411:錯誤/ AndroidRuntime(906):android.content.ActivityNotFoundException:找不到活動處理意圖{動作= android.intent.action.VIEW DAT = HTTP://本地主機:4567典型應用=/vnd.android.package歸檔}

任何想法?

的Android

// first way 
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://localhost:4567")); 

// second way 
// Intent intent = new Intent(Intent.ACTION_VIEW); 
// intent.setDataAndType(Uri.parse("http://localhost:4567"), 
//      "application/vnd.android.package-archive"); 
startActivity(intent); 

西納特拉

require 'sinatra' 

get "/" do 
    content_type "application/vnd.android.package-archive" 
    attachment('agatha_v4.0.apk') 
    file = File.open("agatha.apk", "rb") 
    response.write(file.read) 
end 

回答

3
Intent intent = new Intent(Intent.ACTION_VIEW); 
      intent.setDataAndType(Uri.fromFile(new File 
        (Environment.getExternalStorageDirectory() + "/download/" + "app.apk")), "application/vnd.android.package-archive"); 
      context.startActivity(intent); 
+0

/download/app.apk當然是您在下載時保存它的地方 – Pyrodante

+0

同意。 Android僅支持'file:///'和'content://'方案來安裝APK。 – CommonsWare

+0

所以答案是你*有*下載文件,然後安裝它。當我這樣做並嘗試安裝該文件時,我收到了「解析軟件包時出現問題」的錯誤消息,即使我已檢查下載的文件是否存在問題,但將其複製到設備後成功安裝。 – chris

1

這裏是爲我工作在Android方面。正如Pyrodante提到的,您必須先下載文件。我發現的另一個問題是該文件必須設置爲MODE_WORLD_READBALE(MODE_PRIVATE)失敗。

final String APP_FILE_NAME = "agatha.apk"; 
HttpClient http = new DefaultHttpClient(); 
HttpGet request = new HttpGet("http://10.10.100.113:4567"); 

try { 
    HttpResponse response = http.execute(request); 
    InputStream fileStream = response.getEntity().getContent(); 
     FileOutputStream output = openFileOutput(APP_FILE_NAME, MODE_WORLD_READABLE); 

    byte[] buffer = new byte[1024]; 
    int len = 0; 
    while ((len = fileStream.read(buffer)) > 0) { 
     output.write(buffer, 0, len); 
    } 
    fileStream.close(); 
    output.close(); 

} catch (ClientProtocolException e) { 
    e.printStackTrace(); 
} catch (IOException e) { 
    e.printStackTrace(); 
} 

    Intent intent = new Intent(Intent.ACTION_VIEW); 
    intent.setDataAndType(Uri.fromFile(getFileStreamPath(APP_FILE_NAME)), 
         "application/vnd.android.package-archive"); 
    startActivity(intent); 
}