Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActivityCompat.requestPermissions not working

Calling ActivityCompat.requestPermissions does not display the UI dialog box.

ActivityCompat.requestPermissions(MainActivity.this, new String[]{"Manifest.permission.READ_SMS"}, REQUEST_CODE_ASK_PERMISSIONS);

However, if I change the minSDKversion to 23 and run

requestPermissions(new String[]{"android.permission.READ_SMS"}, REQUEST_CODE_ASK_PERMISSIONS);

the dialog appears. Why? BTW. to run it on the emulator requires that the emulator will be targeting API 23.

like image 984
Zvi Avatar asked Sep 19 '15 17:09

Zvi


People also ask

How do I use ActivityCompat?

Sets the permission delegate for ActivityCompat . Gets whether you should show UI with rationale before requesting a permission. Start new activity with options, if able, for which you would like a result when it finished. Start new IntentSender with options, if able, for which you would like a result when it finished.

What is shouldShowRequestPermissionRationale?

shouldShowRequestPermissionRationale return the boolean indicating whether or not we should show UI with rationale for requesting a permission (dangerous permission, ACCESS_FINE_LOCATION) Now in this code (taken from the documentation itself) : if (ContextCompat. checkSelfPermission(thisActivity, Manifest. permission.

How do I use requestpermissions?

Here's an example of using requestPermissions (): First, define the permission (as you did in your post) in the manifest, otherwise, your request will automatically be denied: Next, define a value to handle the permission callback, in onRequestPermissionsResult ():

How to request permission for an activity in Android?

Android provides several methods that can be used to request permission, such as requestPermissions (). ActivityCompat. requestPermissions (MainActivity.this, permissionArray, requestCode); Here permissionArray is an array of type String.

How to display the system permissions dialog in activityresultlauncher?

To display the system permissions dialog when necessary, call the launch () method on the instance of ActivityResultLauncher that you saved in the previous step. After launch () is called, the system permissions dialog appears.

How do I request runtime permissions for call logs and SMS messages?

If you want to request the permissions specific to call logs and SMS messages and publish your app to the Play Store, you must prompt the user to set your app as the default handler for a core system function before requesting these runtime permissions.


1 Answers

Why?

Probably because you have the wrong permission name in the first code snippet. Either use:

Manifest.permission.READ_SMS

or use:

"android.permission.READ_SMS"

Do not use:

"Manifest.permission.READ_SMS"
like image 61
CommonsWare Avatar answered Oct 15 '22 18:10

CommonsWare