首页 > 解决方案 > 调用需要权限,可能会被用户拒绝:代码应明确检查权限是否可用

问题描述

我收到一个错误CALL_PHONE
如果我删除了调用权限的条件错误
我也在清单中添加了权限但是android studio突出显示CALL_back如果我删除了if的条件那么它会给出一个错误

  private Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_imp_no);

        button = (Button) findViewById(R.id.buttonCall);

        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View arg0) {
                Intent callIntent = new Intent(Intent.ACTION_CALL);
                callIntent.setData(Uri.parse("tel:9990884476"));

                if (ActivityCompat.checkSelfPermission(imp_no.this, Manifest.permission.**CALL_PHONE**) != PackageManager.PERMISSION_GRANTED) {
                    return;
                }
                startActivity(callIntent);
            }
        });
   }
  }

标签: javaandroid

解决方案


您还可以使用 dexter 权限库进行简单的权限检查


推荐阅读