ActivityCompat.requestPermissions not working

Invoking ActivityCompat.requestPermissions does not display the user interface dialog box.

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

However, if I change minSDKversion to 23 and run

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

a dialog box appears. What for? BTW. to run on the emulator requires the emulator to focus on API 23.

+8
android android-6.0-marshmallow
source share
3 answers

Why?

Perhaps because you have the wrong permission name in the first code snippet. Or use:

 Manifest.permission.READ_SMS 

or use:

 "android.permission.READ_SMS" 

Do not use:

 "Manifest.permission.READ_SMS" 
+7
source share

New versions of Android Studio will automatically add the AppCompat library libraries and Android Design support libraries to the build.gradle file when creating a new project. If you do not add the following two lines to the dependencies section of the build.gradle application file.

 compile 'com.android.support:appcompat-v7:23.1.0' compile 'com.android.support:design:23.1.0' 
+1
source share

Make sure that you have already added the requested permission to the Android manifest file, for example, before Android M, only then you will get the expected behavior.

Add manifest permission:

 <uses-permission android:name="android.permission.READ_SMS" /> 
0
source share

All Articles