No Activity found to handle Intent 踩坑记录

爬出坑,做个总结。


在做自动下载更新时,下载完apk后要自动打开安装,使用Intent的setDataAndType方法打开apk类型文件。

发现报错

No Activity found to handle Intent { act=android.intent.action.VIEW

查看该方法

publicIntentsetDataAndType(Uri data,String type) {

mData= data;

mType= type;

return this;

}

使用android自带的DownloadManage下载类,通过

Uri downloadFileUri =downloadManager.getUriForDownloadedFile(downloadId);

获取的Uri地址,发现该地址是content://开头,

乐视手机系统等其它手机无法通过该uri地址找到对应的下载安装包,所以将实际的下载路径转为uri地址即可打开

filename是apk存储的绝对路径

if(!path.equals("")&&path!=null){

downloadFileUri=Uri.parse("file://"+filename);

}

你可能感兴趣的:(No Activity found to handle Intent 踩坑记录)