简体   繁体   中英

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.

However, I encounter the following error when trying to install the apk: java.lang.SecurityException: Caller is not allowed to install APKs

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. Only in this case INSTALL_PACKAGES permission works. Other easy way, just call the url of apk and let system default package manager to handle the job :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM