android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=file:///storage/emulated/0/download/218 typ=application/vnd.android.package-archive flg=0x10000000 }
报错日志如上。
原因:
权限问题。需要加provider访问文件
并在打开页面的时候进行版本判断
Intent intent = new Intent(); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setAction(Intent.ACTION_VIEW); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); try { Uri contentUri = FileProvider.getUriForFile(mContext, mContext.getPackageName() + ".provider", apkfile); intent.setDataAndType(contentUri, "application/vnd.android.package-archive"); } catch (Exception e) { e.printStackTrace(); } } else { intent.setDataAndType(Uri.fromFile(apkfile), "application/vnd.android.package-archive"); } mContext.startActivity(intent);