2011-08-09 134 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); 
}