Skip to content

Commit

Permalink
Adjust Bluetooth permission handling for Android SDK >= 31
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Nov 17, 2022
1 parent 4dcd70d commit 2fe8800
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
10 changes: 8 additions & 2 deletions platform/android/AndroidManifest.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH"
android:maxSdkVersion="30"
/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"
android:maxSdkVersion="30"
/>
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28"
Expand Down
32 changes: 23 additions & 9 deletions platform/android/src/ch/opengis/qfield/QFieldActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -868,15 +868,29 @@ private void checkPermissions() {
PackageManager.PERMISSION_DENIED) {
permissionsList.add(Manifest.permission.ACCESS_MEDIA_LOCATION);
}
if (ContextCompat.checkSelfPermission(QFieldActivity.this,
Manifest.permission.BLUETOOTH) ==
PackageManager.PERMISSION_DENIED) {
permissionsList.add(Manifest.permission.BLUETOOTH);
}
if (ContextCompat.checkSelfPermission(
QFieldActivity.this, Manifest.permission.BLUETOOTH_ADMIN) ==
PackageManager.PERMISSION_DENIED) {
permissionsList.add(Manifest.permission.BLUETOOTH_ADMIN);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
if (ContextCompat.checkSelfPermission(
QFieldActivity.this, Manifest.permission.BLUETOOTH_SCAN) ==
PackageManager.PERMISSION_DENIED) {
permissionsList.add(Manifest.permission.BLUETOOTH_SCAN);
}
if (ContextCompat.checkSelfPermission(
QFieldActivity.this,
Manifest.permission.BLUETOOTH_CONNECT) ==
PackageManager.PERMISSION_DENIED) {
permissionsList.add(Manifest.permission.BLUETOOTH_CONNECT);
}
} else {
if (ContextCompat.checkSelfPermission(
QFieldActivity.this, Manifest.permission.BLUETOOTH) ==
PackageManager.PERMISSION_DENIED) {
permissionsList.add(Manifest.permission.BLUETOOTH);
}
if (ContextCompat.checkSelfPermission(
QFieldActivity.this, Manifest.permission.BLUETOOTH_ADMIN) ==
PackageManager.PERMISSION_DENIED) {
permissionsList.add(Manifest.permission.BLUETOOTH_ADMIN);
}
}
if (permissionsList.size() > 0) {
String[] permissions = new String[permissionsList.size()];
Expand Down

1 comment on commit 2fe8800

@qfield-fairy
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.