Search code examples
androidandroid-permissions

Installing apk from android application running Oreo and having no REQUEST_INSTALL_PACKAGES


I am developing an Android application that has an Autoupdate feature, the android device I am developing this app for has not google play so I had to upload the new apk for the new version somewhere when there is update and check programmatically each time the application is opened if there is a new version, and if there is one I download it (the apk) then installing using this code

Uri apkUri = FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID + ".provider", file);
Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
intent.setData(apkUri);
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivityForResult(intent, 123);

it was working without any problem because the device running the app was running android 7. Recently, the device upgraded to Android 8, and the feature stopped working, after searching many days I found that I have to take a permission called REQUEST_INSTALL_PACKAGE to install a new package https://developer.android.com/reference/android/Manifest.permission.html#REQUEST_INSTALL_PACKAGES starting from Android API 25 as the docs says in this link. I have now two problems;

First: I did not inculde this permission in the old apk, so all users of the old apk will have to uninstall the old apk and install manually the new one (the new one is the one having the REQUEST_INSTALL_PACKAGE perm)

Second: even if they did that, the code I am using up there takes the users to a screen with a scary message describing to them "who bad is installing the new apk and they are responsible for that action". I am attaching a screenshot for the message, I need to remove this message even if there is certificate I need to buy from google, I searched for that but found nothing

enter image description here

any solution, thanks in advance


Solution

  • I need to remove this message even if there is certificate I need to buy from google

    Sorry, there is no way to remove this message. Note that it only will appear once; if the user grants your app the ability to install apps, then future ACTION_INSTALL_PACKAGE requests should not display the message.

    I did not inculde this permission in the old apk, so all users of the old apk will have to uninstall the old apk and install manually the new one

    They do not need to uninstall the old app. They do have to manually install the update, but there is no need to remove the old one.