在Android使用activity中进行apk进行安装的时候,出现的报错。
原因是android.uid.system限制了使用该方法。
修改的方法:
frameworks\base\services\core\java\com\android\server\am\ActivityManagerService.java
final int callingAppId = UserHandle.getAppId(callingUid);if ((callingAppId == SYSTEM_UID) || (callingAppId == ROOT_UID)) {if ("com.android.settings.files".equals(grantUri.uri.getAuthority()) || "com.xxxxxxxx.fileProvider".equals(grantUri.uri.getAuthority())) {// Exempted authority for// 1. cropping user photos and sharing a generated license html// file in Settings app// 2. sharing a generated license html file in TvSettings app} else {Slog.w(TAG, "For security reasons, the system cannot issue a Uri permission"+ " grant to " + grantUri + "; use startActivityAsCaller() instead");return -1;}}
修改:其中com.xxxxxxxx.fileProvider就是你要加入的FileProvider的Authority,这是唯一值。
其中在自己的代码安装apk是这样写的:
File apkFile = new File("/sdcard/downapp/apkfile.apk");Uri apk_fileUri = null;String install_file_provider_authority = "com.xxxxxxxx.fileProvider";try {apk_fileUri = FileProvider.getUriForFile(mContext, install_file_provider_authority, apkFile);} catch (Exception e) {e.printStackTrace();}Intent intent = new Intent();intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);intent.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | FLAG_GRANT_WRITE_URI_PERMISSION);intent.setAction(android.content.Intent.ACTION_VIEW);intent.setDataAndType(apk_fileUri, "application/vnd.android.package-archive");mContext.startActivity(intent);
其中
AndroidManifest.xml
对应的file_paths文件:
对应的地址是:/sdcard/downapp/
这样就完成了错误的修改!完美!
下一篇:矩阵打印问题