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页面有重叠现象,让我十分不爽.研究了一天,终于明白其中的原理并加以解决.解决办法如下: 如果系统内存不 ...
随机推荐
- ios 集合总结
NSArray 用于对象有序集合(相当于是数组) 它有两个限制: 1. 它只能存储objective-c的对象,但不能存储C中的基本数据类型,如int , float, enum, struct等. ...
- Windows下Apache+Django+mod_wsgi的static和media问题处理
配置好了Apache可以访问Django工程了(参见前篇:Windows编译安装mod_wsgi,配合使用Django+Apahce) 但是Django中的static.media等文件Apache是 ...
- Linux -- 统计文件的行数
统计单个文件有多少行 方法1: awk '{print NR}' test1.sh|tail -n1 方法2: awk 'END{print NR}' test1.sh 方法3: grep -n &q ...
- android--listview设置高度
android:layout_height="25dp"这么设置根本就没有用. 我们必须要设置android:minHeight="25dp"这样才行.
- Code Blocks 使用 VC2013编译HelloWord
首先在 Settings-Complier中把 Microsoft Visual c++ 2010 设置成默认(莫不默认也无所谓,就是改着方便而已) 然后在ToolChain excutable 中, ...
- Python 数据挖掘 工具包整理
连接器与io 数据库 类别 Python R MySQL mysql-connector-python(官方) RMySQL Oracle cx_Oracle ROracle MongoDB pymo ...
- jq的合成事件
jq中有两个合成事件 hover()和toggle() 1.hover() hover方法用于模拟光标悬停事件.当光标移动到元素上时,会触发指定的第一个函数(enter),当光标移出这个元素时,会触发 ...
- JS中substr和substring的用法和区别
substr 和 substring都是JS 截取字符串函数,两者用法很相近,下面是两者的语法很示例: substr 方法 返回一个从指定位置开始的指定长度的子字符串.stringvar.substr ...
- MusiCode 批量下载指定歌手的所有专辑(已解除验证码限制)
一直想把喜欢的歌手的专辑全都归类并下载下来,由于那专辑数量实在太多了,再加上最近开始学习python,就想着何不用python写个脚本把下载过程自动化呢?所以就花了点时间写了这么个东西,分享给有需要的 ...
- zf-关于邵阳市打印模块个别单号打印之后不会跳转到收费模块的BUG的解决方法
原因是 办结的时候 有个收费管理,里面会生成收费项目的单号,但是有1个单号是有问题的,没有关联到数据库里面的其他的表,所以打印之后不能跳转.如果跳转到收费模块 那么数据库里面的一个flag字段会变成9 ...