Android RunTime Permission not granting other permission in the same group - android

If i request two Permissions from same Group(Ex READ_CONTACTS , WRITE_CONTACTS) one after another the permission dialog asks the user to accept the permission from same group twice, however the documentation mentions if i accept a permission from same group, android automatically grants rest of the permissions in that group.
ex code:
ActivityCompat.requestPermissions((Activity) currentContext,
new String[]{Manifest.permission.READ_CONTACT},
MY_PERMISSIONS_REQUEST);
as it should work a dialog appears requesting the permission,
however it appears again if i call the following code
ActivityCompat.requestPermissions((Activity) currentContext,
new String[]{Manifest.permission.WRITE_CONTACT},
MY_PERMISSIONS_REQUEST);
so a dialog for permissions from same group appears twice.
Is there a way where i can show only single dialog for permission of same group if i request them in the above fashion ie individually and not together?

The documentation says :
The dialog box shown by the system describes the permission group your
app needs access to; it does not list the specific permission. For
example, if you request the READ_CONTACTS permission, the system
dialog box just says your app needs access to the device's contacts.
The user only needs to grant permission once for each permission
group. If your app requests any other permissions in that group (that
are listed in your app manifest), the system automatically grants
them. When you request the permission, the system calls your
onRequestPermissionsResult() callback method and passes
PERMISSION_GRANTED, the same way it would if the user had explicitly
granted your request through the system dialog box.
That mean that only one alert will be shown for group but you have to request each permissions of this group.
So you should request several permissions in same time :
ActivityCompat.requestPermissions((Activity) currentContext,
new String[]{Manifest.permission.READ_CONTACT, Manifest.permission.WRITE_CONTACT},
MY_PERMISSIONS_REQUEST);
EDIT
To check if permission is already granted you have to use :
if (ContextCompat.checkSelfPermission(thisActivity,
Manifest.permission.READ_CONTACTS)
!= PackageManager.PERMISSION_GRANTED) {
// ...
}

Related

MAUI app under Android hot to give write permission to BlazorWebView

I'm developing a MAUI Blazor app that should run under windows and android
On Android I get an error from a component that tries to write on the clipboard
blazor.webview.js:1 Write permission denied.
Reading this doc I cannot figure out where and how to call the BlazorWebViewInizializing event to allow this permission
Or should I do something also in the AndroidManifest.xml?
Thanks
For this, you can check document Permissions.
In android, Permissions must have the matching attributes set in the Android Manifest file. Permission status defaults to Denied.
Above article describes how you can use the .NET Multi-platform App UI (.NET MAUI) Permissions class. This class allows you to check and request permissions at run-time. The Permissions type is available in the Microsoft.Maui.ApplicationModel namespace.
Checking permissions:
To check the current status of a permission, use the Permissions.CheckStatusAsync method along with the specific permission to get the status for. The following example checks the status of the LocationWhenInUse permission:
PermissionStatus status = await Permissions.CheckStatusAsync<Permissions.LocationWhenInUse>();
Requesting permissions:
To request a permission from the users, use the Permissions.RequestAsync method along with the specific permission to request. If the user previously granted permission, and hasn't revoked it, then this method will return Granted without showing a dialog to the user. The following example requests the LocationWhenInUse permission:
PermissionStatus status = await Permissions.RequestAsync<Permissions.LocationWhenInUse>();
For more information, you can check document Permissions.

Does Anyone knows Where this permission come from and how to grant this programmatically in Android?

I want to create a file explorer , after a lot searching , I found out that I can't Modify , delete or create files on SD card without SAF(Storage Access Framework) on API 25 and higher.Then I installed Some File Manager for Testing how do They Work. All of Them use SAF except Xiaomi File Manager. Xiaomi's only grants a permission. I captured some screenshots.enter image description here
enter image description here
EDIT 1 : I get all my runtime permissions.
thanks for reading :)
Android defines basically three types of permissions:
Normal Permissions
Signature Permissions
Dangerous Permissions
Both Normal and Dangerous permissions must be defined in the Manifest file. But only Dangerous permissions are checked at runtime, Normal permissions are not.
Normal Permissions
Some permissions are automatically granted to the application. Just we need to declare those permissions in AndroidManifest.xml and it will work fine. Those permissions are called Normal Permissions. An example of a normal permission is INTERNET.
list of Normal Permissions: https://developer.android.com/guide/topics/permissions/overview
Signature Permissions
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.
Dangerous Permissions
Some permissions may affect the users private information, or could potentially affect his data or the operation of other application are called Dangerous Permissions. For example, the ability to read the user’s contacts is a dangerous permission. Some other examples are CONTACTS , CAMERA ,CALENDAR, LOCATION , PHONE , STORAGE , SENSORS , MICROPHONE, etc.
Dangerous permissions must be granted by the user at runtime to the app.
Here is an example for requesting a Dangerous Permissions on runtime :-
First, add permissions to AndroidManifest.xml file
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
then ask for permission from user during runtime, like this:-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (checkSelfPermission(Manifest.permission.CAMERA)!= PackageManager.PERMISSION_GRANTED) {
if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{Manifest.permission.CAMERA,Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
}
}else {
dispatchTakePictureIntent();
}
}
Then override the onRequestPermissionsResult method according to your need
#Override
public void onRequestPermissionsResult(int requestCode, #NonNull String[] permissions, #NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == 1){
if (grantResults[0] == PackageManager.PERMISSION_GRANTED){
Toast.makeText(this, "Permission Granted", Toast.LENGTH_SHORT).show();
do your stuff...
}else {
Toast.makeText(this,"Permission Denied",Toast.LENGTH_SHORT).show();
}
}
}
For more information check out this article : https://medium.com/programming-lite/runtime-permissions-in-android-7496a5f3de55
I found it after too many searching in Stack Overflow , So there is a flag that call that dialog and get the uri of the storage ,but this way only works with android 7 to 10.
here is answer of my question :
question answer

android registerContentObserver for Contacts requires READ_CONTACTS permission

I just discovered that, during app initialization my registerContentObserver for Contacts requires READ_CONTACTS permission. Obviously, for a new user on Android 6 and later, this permission won't yet be granted.
It seems to me it would be sufficient to ignore the permission during registration and check permission when the app listener tries to access contacts - which I'm sure it already does.
Same for Calendar.
Should I make an Android change request - why is this coding "penalty" being imposed?

How do I show permissions rationale for multiple permissions request?

I am working with Android API 25 and need to make permissions requests in the app.
There are a ton of code samples on how to make a request as well as how to show the rationale. This link here shows a simple methodology as do these: Android M Request Multiple permission at a single time , Android M request permission non activity
The problem I am having is I am requesting multiple permissions at once (Location, Write storage access, and Contacts) and the ActivityCompatApi23.shouldShowRequestPermissionRationale source code only takes in a String for a single permission and not an array for multiple permissions. (source: android.support.v4.app.ActivityCompat)
So in my code, I can do this:
ActivityCompat.requestPermissions(activity, permissionsStringArray, 123);
And try to request multiple at once, but I can't then show the explanation for the ones needed if they return true from:
ActivityCompat.shouldShowRequestPermissionRationale(activity,
currentPerm.getPermissionManifestName()
Does anyone have any recommendations on how I can show a dialog that includes multiple rationales in it as opposed to one at a time?
I recommend this open source.
https://github.com/ParkSangGwon/TedPermission
You can use simply. for example
private void CheckPermission() {
new TedPermission(this)
.setPermissionListener(permissionlistener)
.setDeniedMessage(getString(R.string.str_permission1))
.setPermissions(Manifest.permission.CAMERA, android.Manifest.permission.READ_PHONE_STATE, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE)
.check();
}

Android 6.0 permission.GET_ACCOUNTS

I'm using this to get permission:
if (ContextCompat.checkSelfPermission(context, Manifest.permission.GET_ACCOUNTS) != PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(context, Manifest.permission.GET_ACCOUNTS)) {
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(context, new String[]{Manifest.permission.GET_ACCOUNTS}, PERMISSIONS_REQUEST_GET_ACCOUNTS);
// MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
// app-defined int constant. The callback method gets the
// result of the request.
}
}
But the pop up dialog for permission asks user for access Contacts!?!?
In pre 6.0 in Play Store with
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
request is named Identity and explains I need it to get device account.
That is because of Permission Groups. Basically, permissions are placed under different groups and all permissions from that group would be granted if one of them is granted.
Eg. Under "Contacts" , there is write/read contacts and get accounts, so when you ask for any of those, the popup asks for Contacts permissions.
Read through: Everything every Android Developer must know about new Android's Runtime Permission
EDIT 1
Just thought i'l add the related(not to get accounts but permissions and groups) Oreo update info:
source: https://developer.android.com/about/versions/oreo/android-8.0-changes.html#rmp
Prior to Android 8.0 (API level 26), if an app requested a permission
at runtime and the permission was granted, the system also incorrectly
granted the app the rest of the permissions that belonged to the same
permission group, and that were registered in the manifest.
For apps targeting Android 8.0, this behavior has been corrected. The
app is granted only the permissions it has explicitly requested.
However, once the user grants a permission to the app, all subsequent
requests for permissions in that permission group are automatically
granted.
GET_ACCOUNTS was moved into the CONTACTS permission group in Android 6.0. While the API has us provide permissions, the user (for Android 6.0 at least) is prompted for permission groups. Hence, the user will be given the same prompt for GET_ACCOUNTS as the user would get for READ_CONTACTS or WRITE_CONTACTS.
Fortunately this will change in Android N
http://developer.android.com/preview/behavior-changes.html#perm
The GET_ACCOUNTS permission is now deprecated. The system ignores this
permission for apps that target Android N.
In Marshmallow all dangerous permissions belong to permission groups.
The permission android.permission.GET_ACCOUNTS belongs to CONTACTS group
You can find more information about dangerous permission and their groups here:
https://developer.android.com/guide/topics/security/permissions.html#normal-dangerous
I got your question wrong first. On this page http://developer.android.com/guide/topics/security/permissions.html#perm-groups, your can see that GET_ACCOUNTS refers to the permission group contacts. Because of that your are prompted for contact permission.
If your using the GET_ACCOUNTS permission to ask the user to select a particular account type on the device(Google in my case), you can use the AccountPicker class which doesn't require any special permissions
Intent intent = AccountPicker.newChooseAccountIntent(null, null,
new String[]{GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE},
false, null, null, null, null);
try {
startActivityForResult(intent, REQUEST_ACCOUNT_PICKER);
} catch (ActivityNotFoundException e) {
// This device may not have Google Play Services installed.
}
You'll need Google Play services auth in your gradle dependencies
implementation com.google.android.gms:play-services-auth:16.0.1
This avoids the Contacts permission popup for me

Categories

Resources