出于某种原因,每次都会显示我的权限检查对话框,但它应该只显示一次:
我有以下代码检查onCreate()
中的短信权限:
if (ContextCompat.checkSelfPermission(MainActivity.this,
Manifest.permission.READ_CONTACTS)
!= PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this,
Manifest.permission.SEND_SMS)) {
Toast.makeText(MainActivity.this, "You should enable", Toast.LENGTH_SHORT).show();
/*ActivityCompat.requestPermissions(MainActivity.this,
new String[]{Manifest.permission.SEND_SMS}, 1001
);*/
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(MainActivity.this,
new String[]{Manifest.permission.SEND_SMS}, 1
);
}
}
问题是,即使用户 点击onCreate
中的启用,该应用也会在用户下次打开应用时打开权限对话框。不应该授予权限,并且对话框不会再次显示?
答案 0 :(得分:1)
您正在检查Manifest.permission.READ_CONTACTS而不是Manifest.permission.SEND_SMS