我正在为新的Android 12蓝牙权限而挣扎。由于某种原因,我的蓝牙权限被自动拒绝,我收到了这个警告消息:Can request only one set of permissions at a time
下面是我的代码:
public void requestBluetooth() {
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.BLUETOOTH_CONNECT)
!= PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
beforeBluetoothGranted = ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.BLUETOOTH_CONNECT);
if (beforeBluetoothGranted) {
new AlertDialog.Builder(MainActivity.this)
.setTitle("Warning")
.setMessage("App must grant Bluetooth permissions in order for BiSym to operate!")
.setCancelable(false)
.setNeutralButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
ActivityCompat.requestPermissions(MainActivity.this,
new String[]{Manifest.permission.BLUETOOTH_CONNECT}, MY_PERMISSIONS_REQUEST_BLUETOOTH);
}
})
.show();
} else {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.BLUETOOTH_CONNECT},
MY_PERMISSIONS_REQUEST_BLUETOOTH);
}
}
} else {
requestBluetoothScan();
}
}
public void requestBluetoothScan() {
//does the same as requestBluetooth for the scan permissions
}
public void onRequestPermissionsResult(int requestCode,
String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
...
case MY_PERMISSIONS_REQUEST_BLUETOOTH:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
requestBluetoothScan();
} else {
afterBluetoothGranted = ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.BLUETOOTH_CONNECT);
}
if (!(beforeBluetoothGranted || afterBluetoothGranted)) {
gotoSettings();
}
}
break;
case MY_PERMISSIONS_REQUEST_BLUETOOTH_SCAN:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
if (!mApp.trialShown) {
openWhatsNewDialog();
}
} else {
afterBluetoothGranted = ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.BLUETOOTH_SCAN);
}
if (!(beforeBluetoothScanGranted || afterBluetoothScanGranted)) {
gotoSettings();
}
}
break;
}
}
我做错了什么?蓝牙对我们应用的功能至关重要。我是Android 12蓝牙权限的新手,权限会自动被拒绝似乎不对。
1条答案
按热度按时间7cwmlq891#
在旅客名单上失踪了吗
主要活动中
英语很差抱歉:)