[英]java.lang.SecurityException Not allowed to install apk from another android application
I am developing an Android app in which I am trying to download from a location(a website) an apk, store it on the sd card and I want to install it on my device. 我正在开发一个Android应用程序,其中我尝试从一个位置(一个网站)下载apk,并将其存储在sd卡中,然后将其安装在我的设备上。
However, I encounter the following error when trying to install the apk: java.lang.SecurityException: Caller is not allowed to install APKs 但是,尝试安装apk时遇到以下错误:java.lang.SecurityException:不允许调用方安装APK。
Any suggestions on why the exception appears? 关于为什么会出现异常的任何建议?
For installing I do the following: 对于安装,请执行以下操作:
public static void installApk(ContentResolver contentResolver) {
final ContentValues values = new ContentValues();
values.put(APK_KEY, APK_NAME);
values.put(PACKAGE_KEY, PACKAGE_NAME);
values.put(APKS_DIR_PATH_KEY, Environment.getExternalStorageDirectory() + APKS_DIR_PATH + APK_NAME);
try {
contentResolver.insert(INSTALL_SINGLE_URI, values);
} catch (SecurityException e) {
//permission not granted
Log.e(Utils.class.getSimpleName(), e.toString());
} }
Firstly you must add this to manifest 首先,您必须将此添加到清单
<uses-permission android:name="android.permission.INSTALL_PACKAGES" />
But now the hard one comes. 但是现在困难的时刻到了。 If you want to install packages from your app, you have to install your app to /system/app.
如果要从应用程序安装软件包,则必须将应用程序安装到/ system / app。 Only in this case INSTALL_PACKAGES permission works.
仅在这种情况下,INSTALL_PACKAGES权限才有效。 Other easy way, just call the url of apk and let system default package manager to handle the job :)
其他简单的方法,只需调用apk的url,然后让系统默认的程序包管理器来处理此工作即可:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.