Bluetooth Request Permisdion

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

For bluetooth permission on Android 12, you need these permission, depend on your

usage:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />


<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-feature android:name="android.hardware.nfc" android:required="true" />
<uses-feature android:name="android.hardware.bluetooth_le"
android:required="true" />
In your activity, you can add this to check the permission is allowed or not:

private static final int ACCESS_COARSE_LOCATION_RESULT_CODE = 4;


private static final int BLUETOOTH_RESULT_CODE = 5;
private static final int DANGEROUS_RESULT_CODE = 1;

if (ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.ACCESS_COARSE_LOCATION},
ACCESS_COARSE_LOCATION_RESULT_CODE);
}
else if (ContextCompat.checkSelfPermission(this,
Manifest.permission.BLUETOOTH) !=
PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.BLUETOOTH},
BLUETOOTH_RESULT_CODE);
}
else if(ContextCompat.checkSelfPermission(this,
Manifest.permission.BLUETOOTH_SCAN) !=
PackageManager.PERMISSION_GRANTED){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.BLUETOOTH_SCAN},
DANGEROUS_RESULT_CODE);
}
}
else if(ContextCompat.checkSelfPermission(this,
Manifest.permission.BLUETOOTH_CONNECT) !=
PackageManager.PERMISSION_GRANTED){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.BLUETOOTH_CONNECT},
DANGEROUS_RESULT_CODE);
}
}

You might also like