如何在MIUI 8+中获取读取“服务SMS”的权限(以编程方式)

问题描述 投票:0回答:1

如何检查阅读服务我的MI手机应用程序关闭/开启短信权限。我正在构建一个应用程序,我需要从手机上阅读短信。现在对于MI手机,一些短信转到通知消息并阅读它们我需要服务短信权限。下面是它的截图。

enter image description here

android permissions sms
1个回答
2
投票

如果您在短信读取代码之前调用requestSmsPermission(),则需要获得所有必要的许可

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();
        }
    }

}
© www.soinside.com 2019 - 2024. All rights reserved.