我有一个基本上能够拦截各种链接,视频,apks,hrefs的web视图。Android的自动安装APK
现在,我要的是有一次我从一个网址下载一个APK,它会自动安装:
这是shouldOverrideUrlLoading()
代码的一部分:
else if(url.endsWith(".apk"))
{
mWebView.setDownloadListener(new DownloadListener() {
public void onDownloadStart(final String url, String userAgent,
String contentDisposition, String mimetype,
long contentLength) {
}
});
Intent intent = new Intent(Intent.ACTION_VIEW ,Uri.parse(url));
startActivity(intent);
return true;
如果我添加
intent.setDataAndType(Uri.parse(url), "application/vnd.android.package-archive");
比应用程序崩溃...
任何想法,为w做帽子?
编辑:我是能够自动启动程序包的下载和安装(使用睡眠()):
else if(url.endsWith(".apk"))
{
mWebView.setDownloadListener(new DownloadListener() {
public void onDownloadStart(final String url, String userAgent,
String contentDisposition, String mimetype,
long contentLength) {
}
});
Intent intent = new Intent(Intent.ACTION_VIEW ,Uri.parse(url));
startActivity(intent);
String fileName = Environment.getExternalStorageDirectory() + "/download/" + url.substring(url.lastIndexOf('/')+1, url.length());
install(fileName);
return true;
,并为vitamoe建议:
protected void install(String fileName) {
Intent install = new Intent(Intent.ACTION_VIEW);
install.setDataAndType(Uri.fromFile(new File(fileName)),
"application/vnd.android.package-archive");
startActivity(install);
}
然而,我无法捕获完成下载的确切时间,可能需要创建我自己的下载功能,而不是使用浏览器的一个,任何想法?
如果您发布了错误日志,它会有帮助。 – DKIT 2011-05-24 10:56:12
请发布整个webview.java文件 – 2011-09-08 23:37:34