项目中,进行版本更新的时候,用的是自己写的下载方案,最近看到了使用系统服务 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 的解决办法的更多相关文章

  1. Android:使用 DownloadManager 进行版本更新,出现 No Activity found to handle Intent 及解决办法

    项目中,进行版本更新的时候,用的是自己写的下载方案,最近看到了使用系统服务 DownloadManager 进行版本更新,自己也试试. 在下载完成以后,安装更新的时候,出现了一个 crash,抓取的 ...

  2. Android开发之bug-No Activity found to handle Intent

    android.content.ActivityNotFoundException: No Activity found to handle Intent 做Android开发中,使用隐式intent ...

  3. ActivityNotFoundException: No Activity found to handle Intent

    代码如下: Intent intent = new Intent(); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setAction ...

  4. 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 = ...

  5. vss登录invalid handle问题的解决办法

    VSS登录出现“invalid handle” 原因:网络验证. 解决方法: 1.打开控制面板:选择“用户帐户和家庭安全” 2.选择凭据管理器: 3.添加Windows 凭据 这一步特别重要: (1) ...

  6. Android:调用其他程序中的activity和Permission Denial: starting Intent 错误解决办法

    今天想调试多个task中栈的情况,在测试程序中调用另一个程序的activity, 代码片段如下: btnStartX=(Button)findViewById(R.id.btnStartX); btn ...

  7. Activity启动模式 及 Intent Flags 与 栈 的关联分析

     http://blog.csdn.net/vipzjyno1/article/details/25463457    Android启动模式Flags栈Task   目录(?)[+] 什么是栈 栈 ...

  8. 【转】Activity启动模式 及 Intent Flags 与 栈 的关联分析

    http://blog.csdn.net/vipzjyno1/article/details/25463457    在学习Android的过程中,Intent是我们最常用Android用于进程内或进 ...

  9. Activity被回收导致fragment的getActivity为null的解决办法

    这两天一直被这个问题困扰,假如app长时间在后台运行,再点击进入会crash,而且fragment页面有重叠现象,让我十分不爽.研究了一天,终于明白其中的原理并加以解决.解决办法如下: 如果系统内存不 ...

随机推荐

  1. 每个程序员都应该学习使用Python或Ruby

    每个程序员都应该学习使用Python或Ruby 如果你是个学生,你应该会C,C++和Java.还会一些VB,或C#/.NET.多少你还可能开发过一些Web网页,你知道一些HTML,CSS和JavaSc ...

  2. linux的mount(挂载)NFS 共享,命令详解

    Linux下挂载(mount)光盘镜像文件.移动硬盘.U盘.Windows和NFS网络共享 linux是一个优秀的开放源码的操作系统,可以运行在大到巨型小到掌上型各类计算机系统上,随着 linux系统 ...

  3. 【摘自网络】dll库和lib库有什么区别

    简单地讲:第一:.DLL是动态链接库,而.LIB是静态链接库dll是个编译好的程序,调用时可以直接调用其中的函数,不参加工程的编译. 而lib应该说是一个程序集, 只是把一些相应的函数总结在一起, 如 ...

  4. 正则抓取网页所有href和src

    根据抓取的页面,用正则来匹配页面href和src string UserAgent = "Mozilla/5.0 (Windows NT 5.2; rv:29.0) Gecko/201001 ...

  5. 【gcd】 最大公约数

    int gcd(int a,int b) { int r; ) { r=a%b; a=b; b=r; } return a; }

  6. Split()特殊字符

    关于点的问题是用string.split("[.]") 解决. 关于竖线的问题用 string.split("\\|")解决. 关于星号的问题用 string. ...

  7. POJ 2019 Cornfields(二维RMQ)

    相比以前的RMQ不同的是,这是一个二维的ST算法 #include<iostream> #include<cstring> #include<cstdio> #in ...

  8. HDU 3201 Build a Fence

    水题 #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> us ...

  9. 集合-字典(Dictionary)

    字典(散列表):允许按照某个键来访问元素,能根据键快速查找元素,也可以自由添加,删除元素.比较像List<T>类,但没有list向后移动元素的性能开销. .net中最主要的字典类是Dict ...

  10. svn branch 的使用

    svn revision graph 中选中 "wc"(Mark current revision of your working copy.)这个选项后, 当前工作副本的版本号会 ...