you need to ask for permission in marshmallow, there is no other way to overcome this issue.
to check permission you can use this
checkSelfPermission(Manifest.permission.READ_CONTACTS);
If permission is given by user, it will return 0 else will return 1.
if permission is not given, ask user for permission
requestPermissions(new String[]{Manifest.permission.READ_CONTACTS},
10);
and check whether user have granted permission or not
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
switch (requestCode) {
case 10:
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// Permission Granted
Toast.makeText(MainActivity.this, "READ_CONTACTS granted", Toast.LENGTH_SHORT)
.show();
} else {
// Permission Denied
Toast.makeText(MainActivity.this, "READ_CONTACTS Denied", Toast.LENGTH_SHORT)
.show();
}
break;
default:
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
for more information, refer this
if you want to give support in pre-marshmallow devices also you need to use
ContextCompat.checkSelfPermission()
ActivityCompat.requestPermissions()
rest all things are same as i mentioned above.