【发布时间】:2016-04-04 19:17:13
【问题描述】:
您好,我想做一个简单的按钮点击,允许用户在按下时拨打特定号码。在 API 23 之前,我的代码只是简单地将权限添加到清单中,然后我们就走了,但现在我必须添加这个自检系统。我遇到的问题
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
因为 (this) 有一个红色下划线,告诉我这是错误的第一个参数类型。既然这是我第一次遇到这个自检问题,我该如何解决这个错误?
call = (Button) findViewById(R.id.btnCall);
call.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:123"));
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
return;
}
startActivity(callIntent);
}
});
谢谢
【问题讨论】:
标签: java android android-studio onclick call