DownloadManager 版本更新,出现 No Activity found to handle Intent 的解决办法
项目中,进行版本更新的时候,用的是自己写的下载方案,最近看到了使用系统服务 DownloadManager 进行版本更新,自己也试试。
在下载完成以后,安装更新的时候,出现了一个 crash,抓取的 log :
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW type=application/vnd.android.package-archive flg=0x10000000 }
代码:
Intent install = new Intent(Intent.ACTION_VIEW);
DownloadManager mManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
Uri downloadFileUri = mManager.getUriForDownloadedFile(downloadApkId);
install.setDataAndType(downloadFileUri, "application/vnd.android.package-archive");
install.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(install);
通过搜索发现应该是传入的 Uri 有问题,安装 apk 的 Uri 应该是 file:// 开头的,但是代码中获取的 Uri 是 content://
修改后的代码:
Intent install = new Intent(Intent.ACTION_VIEW);
Uri downloadFileUri;
File file = context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS + "/update.apk");
if (file != null) {
String path = file.getAbsolutePath();
downloadFileUri = Uri.parse("file://" + path);
install.setDataAndType(downloadFileUri, "application/vnd.android.package-archive");
install.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(install);
}
修改后的代码可以正常进行版本更新了。
DownloadManager 版本更新,出现 No Activity found to handle Intent 的解决办法的更多相关文章
- Android:使用 DownloadManager 进行版本更新,出现 No Activity found to handle Intent 及解决办法
项目中,进行版本更新的时候,用的是自己写的下载方案,最近看到了使用系统服务 DownloadManager 进行版本更新,自己也试试. 在下载完成以后,安装更新的时候,出现了一个 crash,抓取的 ...
- Android开发之bug-No Activity found to handle Intent
android.content.ActivityNotFoundException: No Activity found to handle Intent 做Android开发中,使用隐式intent ...
- ActivityNotFoundException: No Activity found to handle Intent
代码如下: Intent intent = new Intent(); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setAction ...
- android.content.ActivityNotFoundException: No Activity found to handle Intent { (has extras) }
报错: 初始代码: @OnClick(R.id.include_top_iv_more) public void onViewClicked() { Intent intent_chat_set = ...
- vss登录invalid handle问题的解决办法
VSS登录出现“invalid handle” 原因:网络验证. 解决方法: 1.打开控制面板:选择“用户帐户和家庭安全” 2.选择凭据管理器: 3.添加Windows 凭据 这一步特别重要: (1) ...
- Android:调用其他程序中的activity和Permission Denial: starting Intent 错误解决办法
今天想调试多个task中栈的情况,在测试程序中调用另一个程序的activity, 代码片段如下: btnStartX=(Button)findViewById(R.id.btnStartX); btn ...
- Activity启动模式 及 Intent Flags 与 栈 的关联分析
http://blog.csdn.net/vipzjyno1/article/details/25463457 Android启动模式Flags栈Task 目录(?)[+] 什么是栈 栈 ...
- 【转】Activity启动模式 及 Intent Flags 与 栈 的关联分析
http://blog.csdn.net/vipzjyno1/article/details/25463457 在学习Android的过程中,Intent是我们最常用Android用于进程内或进 ...
- Activity被回收导致fragment的getActivity为null的解决办法
这两天一直被这个问题困扰,假如app长时间在后台运行,再点击进入会crash,而且fragment页面有重叠现象,让我十分不爽.研究了一天,终于明白其中的原理并加以解决.解决办法如下: 如果系统内存不 ...
随机推荐
- Codeforces Round #363 (Div. 2)D. Fix a Tree(并查集)
D. Fix a Tree time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- 7、装饰模式(Decorator)
顾名思义,装饰模式就是给一个对象增加一些新的功能,而且是动态的,要求装饰对象和被装饰对象实现同一个接口,装饰对象持有被装饰对象的实例,关系图如下: Source类是被装饰类,Decorator类是一个 ...
- 何查询SQL Server数据库没有主键的表并增加主键
SQL Server数据库中,如果一个表没有主键,我们该如何查询呢?本文我们主要就介绍了如何查询数据库中没有主键的表名并为其增加主键的方法,希望能够对您有所帮助. 该功能的实现代码如下: declar ...
- Best Grass
Description Bessie is planning her day of munching tender spring grass and is gazing out upon the pa ...
- Qt5:窗口居中显示
QDesktopWidget* desktop = QApplication::desktop(); // =qApp->desktop();也可以move((desktop->width ...
- Mac系统下安装Tomcat,以及终端出现No such file or directory的错误提示解决方案
Tomcat,作为一个免费的服务器口碑实在太好,本想安装一个研究研究,无奈电脑是mac系统,在网上搜了一些安装方法总是出错,直到遇到了这篇博客,http://www.cnblogs.com/qingy ...
- Chapter 1 First Sight——5
"He's in a wheelchair now," Charlie continued when I didn't respond, 他现在在轮椅上了,没等我回答查理斯就继续说 ...
- JSONObject转换JSON之将Date转换为指定格式(转)
项目中,经常会用JSONObject插件将JavaBean或List<JavaBean>转换为JSON格式的字符串,而JavaBean的属性有时候会有java.util.Date这个类型的 ...
- 三列布局,读《css那些事儿》
1.两列定宽,中间自适应 要点:浮动.负边距效果.mainbox增加内容div并设置margin.:after清除浮动 原理:mainbox的浮动并将其宽度设置为100%,次要内容及侧边栏设置固定宽度 ...
- 《JavaScript语言精髓与编程实践》读书笔记
JavaScript语言精髓与编程实践读书笔记 function v1(v1){ v1 = 100; alert('v1:'+v1); } function v2(name){ v1.apply(th ...