java - 调用需要权限,可能会被用户拒绝:代码应明确检查权限是否可用
问题描述
我收到一个错误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);
}
});
}
}
解决方案
您还可以使用 dexter 权限库进行简单的权限检查
推荐阅读
- ios - AWS SNS - 多设备推送通知到移动应用程序实例
- c - 需要帮助破译 C 语法
- java - 如何使用 onEntityCollidedWithBlock 使方块召唤爆炸?我的世界改装
- jquery - JQuery 复制一个单选按钮组
- javascript - 基于另一个下拉列表的动态文本框和下拉列表 -javascript
- python - 在 Python 中合并(同时保留值)多个字典的最快方法?
- c++ - 对驻留在函数堆栈上的队列的引用
- matplotlib - 为什么在这种情况下设置固定颜色条失败?
- ios - safeAreaInsets 仅在 iPhone 7 Plus / 8 Plus 上为 0
- sql - Mysql将重复的行列值合并为一行