I am writing code to request several Run time permission on android 6.0
in a group. everything is fine, I am following a good example for this, but still have a problem.
In ActivityCompat.shouldShowRequestPermissionRationale (context, READ_PHONE_STATE)
his mistake in context, which is the
wrong context of the first argument . please help solve it.
Thanks at Advance
Code:
if (ContextCompat
.checkSelfPermission(SpalshActivity.this,
READ_PHONE_STATE)+ContextCompat.checkSelfPermission(context,
WRITE_EXTERNAL_STORAGE) +ContextCompat.checkSelfPermission(context,
CAMERA) + ContextCompat
.checkSelfPermission(context,
READ_CONTACTS)+ContextCompat
.checkSelfPermission(context,
CALL_PHONE)+ContextCompat
.checkSelfPermission(context,
ACCESS_FINE_LOCATION)+ContextCompat
.checkSelfPermission(context,
READ_SMS)== PackageManager.PERMISSION_GRANTED) {
myMethod();
}
else {
if (ActivityCompat.shouldShowRequestPermissionRationale
(context, READ_PHONE_STATE) ||ActivityCompat.shouldShowRequestPermissionRationale
(context, WRITE_EXTERNAL_STORAGE)||
ActivityCompat.shouldShowRequestPermissionRationale
(context, CAMERA) ||
ActivityCompat.shouldShowRequestPermissionRationale
(context, READ_CONTACTS) || ActivityCompat.shouldShowRequestPermissionRationale
(context, CALL_PHONE) || ActivityCompat.shouldShowRequestPermissionRationale
(context, ACCESS_FINE_LOCATION) || ActivityCompat.shouldShowRequestPermissionRationale
(context, READ_SMS)) {
Snackbar.make(findViewById(android.R.id.content),
"Please Grant Permissions",
Snackbar.LENGTH_INDEFINITE).setAction("ENABLE",
new View.OnClickListener() {
@Override
public void onClick(View v) {
ActivityCompat.requestPermissions(SpalshActivity.this,
new String[]{READ_PHONE_STATE,WRITE_EXTERNAL_STORAGE,CAMERA, READ_CONTACTS, CALL_PHONE, ACCESS_FINE_LOCATION, READ_SMS},
REQUEST_READ_PHONE_STATE);
}
}).show();
} else {
ActivityCompat.requestPermissions(SpalshActivity.this,
new String[]{READ_PHONE_STATE,WRITE_EXTERNAL_STORAGE,CAMERA, READ_CONTACTS, CALL_PHONE, ACCESS_FINE_LOCATION, READ_SMS},
REQUEST_READ_PHONE_STATE);
}
}
}
}