0

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());
    }   }
Radu Stejerean
  • 345
  • 2
  • 13
  • 28

1 Answers1

1

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 :)

asozcan
  • 1,370
  • 1
  • 17
  • 24
  • One other issue is that I am using a third party app to install the apk, so I don't really know how to find out if that permission is set in the manifest file of the third party app. – Radu Stejerean Jul 22 '15 at 10:14
  • You can see that app's manifest file and even change it with a basic uncompression app like 7z. But there is too much workaround and not nice :) – asozcan Jul 22 '15 at 13:12