每次对话都会显示?

时间:2016-04-09 19:19:37

标签: java android xml string algorithm

出于某种原因,每次都会显示我的权限检查对话框,但它应该只显示一次:

我有以下代码检查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中的启用,该应用也会在用户下次打开应用时打开权限对话框。不应该授予权限,并且对话框不会再次显示?

1 个答案:

答案 0 :(得分:1)

您正在检查Manifest.permission.READ_CONTACTS而不是Manifest.permission.SEND_SMS