简体   繁体   English

java.lang.SecurityException不允许从另一个Android应用程序安装APK

[英]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.

相关问题 Android:java.lang.SecurityException - Android: java.lang.SecurityException java.lang.SecurityException: - java.lang.SecurityException: Java.lang.securityException - Java.lang.securityException Java.lang.SecurityException:Android中的安全权限? - Java.lang.SecurityException:SECURE PERMISSION in android? 发生Android java.lang.SecurityException - Android java.lang.SecurityException occured 来自NotificationManager的java.lang.SecurityException? - java.lang.SecurityException from NotificationManager? 在 Android 10 上安装更新同一应用程序的 apk 失败; java.lang.SecurityException:文件仍然打开 - Installing apk that updates the same app fails on Android 10; java.lang.SecurityException: Files still open java.lang.SecurityException:不允许在android API级别23中启动服务意图错误 - java.lang.SecurityException: Not allowed to start service Intent error in android api level 23 Android GoogleMaps在某些设备上不工作,显示java.lang.SecurityException:需要INSTALL_LOCATION_PROVIDER权限 - Android GoogleMaps not working on some devices shows java.lang.SecurityException: need INSTALL_LOCATION_PROVIDER permission Android 工作室 java.lang.SecurityException:需要 INSTALL_LOCATION_PROVIDER 权限 - Android studio java.lang.SecurityException: need INSTALL_LOCATION_PROVIDER permission
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM