项目中,进行版本更新的时候,用的是自己写的下载方案,最近看到了使用系统服务 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. vbs打包exe工具

    工具下载:http://yunpan.cn/cceRRbszUt5MC  访问密码 66e2

  2. PAT (Advanced Level) 1115. Counting Nodes in a BST (30)

    简单题.统计一下即可. #include<cstdio> #include<cstring> #include<cmath> #include<vector& ...

  3. 关于Context []startup failed due to previous errors有效解决方式

    http://blog.csdn.net/mcpang/article/details/5468386

  4. linux下GBK->UTF-8文件编码批量转换脚本

    find default -type d -exec mkdir -p utf/{} \;find default -type f -exec iconv -f GBK -t UTF-8 {} -o ...

  5. Processes and Threads (转)

    http://www.cnblogs.com/xitang/archive/2011/09/24/2189460.html 原文 http://developer.android.com/guide/ ...

  6. list转换为map

    Java代码如下: package Test01; import java.util.ArrayList; import java.util.HashMap; import java.util.Lis ...

  7. C​# ​日​期​时​间

    //获取日期+时间 DateTime.Now.ToString(); // 2008-9-4 20:02:10 DateTime.Now.ToLocalTime().ToString(); // 20 ...

  8. 发布时去掉 debug 和 提醒日志,简单无侵入

    在 proguard 文件中加入下面代码,让发布时去掉 debug 和 提醒日志,简单无侵入! -assumenosideeffects class android.util.Log { public ...

  9. 转html5语义化标签总结一

    HTML 5的革新之一:语义化标签一节元素标签. 在HTML 5出来之前,我们用div来表示页面章节,但是这些div都没有实际意义.(即使我们用css样式的id和class形容这块内容的意义).这些标 ...

  10. Android网络开发之Volley--Volley基本用法JsonObjectReques(二)

    1.JsonObjectRequest用法 用法和StringRequest基本相同,主要分为3步: (1).实例化一个RequestQueue对象 (2).设置JsonObjectRequest对象 ...