gpt4 book ai didi

java - 不兼容的类型 Android 允许权限?

转载 作者:行者123 更新时间:2023-11-29 23:22:55 26 4
gpt4 key购买 nike

我在 onCreate 方法中运行此代码以尝试获得许可,但由于某种原因它给了我错误:

Incompatible types required int found boolean for this part: if (ContextCompat.checkSelfPermission(MainActivity.this, android.Manifest.permission.READ_SMS) + ContextCompat.checkSelfPermission(MainActivity.this, android.Manifest.permission.SEND_SMS))

 @Override
protected void onCreate(Bundle savedInstanceState) {


if (ContextCompat.checkSelfPermission(MainActivity.this, android.Manifest.permission.READ_SMS) +
ContextCompat.checkSelfPermission(MainActivity.this, android.Manifest.permission.SEND_SMS))
!= PackageManager.PERMISSION_GRANTED) {
if (AppCompatActivity.shouldShowRequestPermissionRationale(this,"Manifest.permission.READ_SMS") ||
AppCompatActivity.shouldShowRequestPermissionRationale(this,"Manifest.permission.READ_SMS")) {

// Show an explanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.

} else {

// No explanation needed; request the permission
ActivityCompat.requestPermissions(this,
new String[]{"Manifest.permission.READ_SMS, Manifest.permission.SEND_SMS"},
REQUEST_CODE);

// REQUEST_CODE is an
// app-defined int constant. The callback method gets the
// result of the request.
}
}

else {
// Permission has already been granted
}

最佳答案

在“if”条件的开头缺少一个开放的圆括号:

if (ContextCompat.checkSelfPermission(MainActivity.this, android.Manifest.permission.READ_SMS) + ContextCompat.checkSelfPermission(MainActivity.this, android.Manifest.permission.SEND_SMS)) != PackageManager.PERMISSION_GRANTED){......}

您有 3 个左括号和 4 个右括号。

这是你应该拥有的:

if ((ContextCompat.checkSelfPermission(MainActivity.this, android.Manifest.permission.READ_SMS) + ContextCompat.checkSelfPermission(MainActivity.this, android.Manifest.permission.SEND_SMS)) != PackageManager.PERMISSION_GRANTED){.....}

关于java - 不兼容的类型 Android 允许权限?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53956757/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com