Reputation: 155
Disclaimer :
This is not a duplicate of onrequestpermissionsresult grant results always -1 since OP recognized it didn't add the right in the manifest.
It is neither a duplicate of onRequestPermissionsResult returns immediately with denied permission since OP made a spelling mistake in the manifest.
I'm developping an app that needs to install other apps (that we develop in-house and serve on our intranet through a web service). I can't manage to grant the right to install that APK.
Here's what I've done so far:
I've added the right [uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/] in the manifest.
I've toggled the right in "Settings", "Apps & notifications", "Advanced", "Special app access", "Install unknown apps", "My app", "Allow from this source".
-> for an unknown reason, this right toggles off on its own sometimes ???
In the MainActivity of the Android project, in the OnCreate I do :
if (ContextCompat.CheckSelfPermission(this.BaseContext, Manifest.Permission.RequestInstallPackages) != (int)Permission.Granted)
{
RequestPermissions(new String[] { Manifest.Permission.RequestInstallPackages }, 200);
}
The call of this method doesn't display any popup asking for permission.
CheckSelfPermission always return Permission.Denied
After that call, the app immediately steps into :
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults)
{
if (requestCode == 200)
{
...
}
}
grantResults always contains int[1] of value {-1} (Permission Denied)
The device running this app is a rugged handheld Datalogic MEMOR10 with android 8.1.0
I also have the exact same error on my Nokia 3 (Android 9)
It worked on a Zebra TC51 with android 7 (CheckSelfPermission() returns Permission.Granted, even though I never allowed it, but it doesn't matter)
Those are minimal and target version of my project : [uses-sdk android:minSdkVersion="23" android:targetSdkVersion="27" /]
Additional information :
What am I doing wrong ?
What am I missing ?
EDIT : I only discovered later that this method is only if you want to install an app WITHOUT user prompt. If you want to install it with user prompt, this permission is not necessary.
Upvotes: 0
Views: 1336
Reputation: 39843
As documented fo REQUEST_INSTALL_PACKAGES
, it's a permission with
Protection level: signature
This is declared and explained for <permission>
A permission that the system grants only if the requesting application is signed with the same certificate as the application that declared the permission. If the certificates match, the system automatically grants the permission without notifying the user or asking for the user's explicit approval.
If you declare the REQUEST_INSTALL_PACKAGES
permission in your manifest, it gets grated or rejected automatically. The requestPermission()
call is only required for dangerous permissions
A higher-risk permission that would give a requesting application access to private user data or control over the device that can negatively impact the user. Because this type of permission introduces potential risk, the system may not automatically grant it to the requesting application. For example, any dangerous permissions requested by an application may be displayed to the user and require confirmation before proceeding, or some other approach may be taken to avoid the user automatically allowing the use of such facilities.
Upvotes: 3