'Android Studio still throw Call requires permission which may be rejected by user when I have check the permission
When I use android BLE to create a bond,I have check the permission of Manifest.permission.BLUETOOTH_CONNECT before device.createBond();,but Android Studio still throw an error: Call requires permission which may be rejected by user: code should explicitly check to see if permission is available (with checkPermission) or explicitly handle a potential SecurityException
of the line device.createBond();
private final AdapterView.OnItemClickListener bondDeviceClick = (adapterView, view, i, l) -> {
BluetoothDevice device = new ArrayList<>(searchDeviceList).get(i);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.BLUETOOTH_CONNECT}, 0x01);
}
device.createBond();
};
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
