0

Why i get this message

enter image description here

if the i set the permission in the manifest file:

enter image description here

Thank you for any help.

user2671169
  • 203
  • 1
  • 10

5 Answers5

0

You need request permission at runtime in android >= 6.0

https://developer.android.com/training/permissions/requesting.html

0

You have to grant permission in android version >=6.0 (Marshmallow and above).

Rajkiran
  • 15,845
  • 24
  • 74
  • 114
KDeogharkar
  • 10,939
  • 7
  • 51
  • 95
0

For Android 6.0+, you have to request the permission at runtime as well as adding it to the manifest. So something like this added to your Activity onCreate();

List<String> permissions = new ArrayList<>();
permissions.add(Manifest.permission.READ_CONTACTS);
//...add any others you need to this arraylist

// Convert the List to an Array
String[] permissionsArray = permissions.toArray(new String[0]);
ActivityCompat.requestPermissions(getActivity(), permissionsArray, REQUEST_CODE);
//The REQUEST_CODE is just a integer that your callback method will check, set it to some number

Then override this method in your activity to check whether the request was granted or not

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    switch (requestCode) {
    case REQUEST_CODE: {
        if (grantResults.length > 0
            && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

            //Permission Granted, do your thing

        } else {

            //Permission denied, you can't do what you want to because user didn't give you permission

        }
        return;
    }
}

See here for more info https://developer.android.com/training/permissions/requesting.html

wanpanman
  • 378
  • 3
  • 10
0

Change your target sdk version to 22 in your app's build.gradle if you donot want to request the permission to the user at run time.

Else if you want to keep the target sdk version to 23 then you would need to request the permission from the user at run time as mentioned above by @wanpanman

Smit Davda
  • 638
  • 5
  • 15
0

Call this permission.

    //Check permissions
    public boolean reqPermission() {
        if (!Permissions.checkPermission(this, Manifest.permission.READ_CONTACTS)) {
            if (shouldShowRationale(Manifest.permission.READ_CONTACTS)) {
                Snackbar.make(yourLayout, "Need to enable contact permission to use this feature. bla bla bla",
                        Snackbar.LENGTH_INDEFINITE)
                        .setAction(R.string.settings, new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                Intent intent = new Intent();
                                intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                                Uri uri = Uri.fromParts("package", getPackageName(), null);
                                intent.setData(uri);
                                startActivity(intent);
                            }
                        })
                        .show();
                return true;
            } else {
                Permissions.grantPermission(this, PERMISSION_REQUEST_CODE);
                return true;
            }
        } else {
            return false;
        }
    }

@TargetApi(Build.VERSION_CODES.M)
    public  boolean shouldShowRationale(String permission) {
        return shouldShowRequestPermissionRationale(permission);
    }
Laurence Pardz
  • 292
  • 3
  • 8