自定义android应用程序安装
在测试阶段,我需要能够发送更新,而无需通过android商店。我已经找到了一些关于这个的帖子,但是没有一个适合我。该文件本身下载良好,但对于这两种备选方案,我都得到一个错误: 08-09 16:31:20.411:错误/AndroidRuntime(906):android.content.ActivityNotFoundException:未找到可处理Intent的活动{act=android.Intent.action.VIEW dat=http://localhost:4567 typ=application/vnd.android.package-archive} 有什么想法吗 安卓 西纳特拉自定义android应用程序安装,android,Android,在测试阶段,我需要能够发送更新,而无需通过android商店。我已经找到了一些关于这个的帖子,但是没有一个适合我。该文件本身下载良好,但对于这两种备选方案,我都得到一个错误: 08-09 16:31:20.411:错误/AndroidRuntime(906):android.content.ActivityNotFoundException:未找到可处理Intent的活动{act=android.Intent.action.VIEW dat=http://localhost:4567 typ=a
以下是我在安卓方面的工作。正如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);
}
下载时,/download/app.apk当然是您保存它的地方。Android只支持安装APK的
文件:////
和内容://
方案。因此,答案是你必须下载文件,然后安装它。当我这样做并尝试安装该文件时,我会收到一条错误消息“解析包时出现问题”,尽管我已通过在将下载的文件复制到设备后成功安装该文件来检查该文件是否有问题。IIRC我遇到了类似的问题,最终发现主机没有配置application/vnd.android.package-archive。关于确切的原因,我可能是错的,但我记得那个错误,我们已经解决了。我发布的代码是安装下载的APK的实时代码
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
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);
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);
}