Permissions for Android 6.0. Read SMS

I want to get permission to read SMS in my application. This is my code:

String permission = Manifest.permission.READ_SMS;
if (ContextCompat.checkSelfPermission(getContext(), permission) != PackageManager.PERMISSION_GRANTED){
    permissionList.add(permission);

    if (!ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), permission)){
        requestPermissions(new String[]{permission}), SMS_PERMISSION);
    }
}

I did not receive a dialog to confirm the request for permission. For other permissions (e.g. WRITE_STORAGE, READ_CONTACTS) I got this dialog. Do you know how to fix this?

The method onRequestPermissionsResultgives me that permission is not granted. But it works without a confirmation dialog.

+4
source share
3 answers

I need a dialog box <uses-permission-sdk-23/>to confirm.

+1
source

Have you added permission read_smsto AndroidManifest.xml?

0
source
int GET_MY_PERMISSION = 1;
if(ContextCompat.checkSelfPermission(MainActivity.this,Manifest.permission.READ_SMS)
            != PackageManager.PERMISSION_GRANTED){
        if(ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this,
                Manifest.permission.READ_SMS)){
            /* do nothing*/
        }
        else{

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

this piece of code is working fine. I used it in Nougat (api level: 25) I hope it should work for you! I followed this

0
source

Source: https://habr.com/ru/post/1624956/


All Articles