How to check read service SMS permission is off/on for My application of MI phone. I am building an application where I need to read SMS from phone. Now for MI phone some SMS goes to Notification message and to read them I need a service sms permission on. Below is the screenshot of it.
Asked
Active
Viewed 856 times
0
-
just follow the link [stackoverflowlink](https://stackoverflow.com/questions/45032638/how-to-get-permission-for-read-service-sms-in-miui-8-programmatically) – amit ghosh Nov 24 '17 at 22:20
1 Answers
1
It will take all necessary permission if you just call requestSmsPermission()
before your sms read code
private void requestSmsPermission() {
String permission = Manifest.permission.READ_SMS;
int grant = ContextCompat.checkSelfPermission(this, permission);
if (grant != PackageManager.PERMISSION_GRANTED) {
String[] permission_list = new String[1];
permission_list[0] = permission;
ActivityCompat.requestPermissions(this, permission_list, 1);
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == 1) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Toast.makeText(AccountClass.this,"permission granted", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(AccountClass.this,"permission not granted", Toast.LENGTH_SHORT).show();
}
}
}

amit ghosh
- 81
- 7