Skip to content

Commit 9de39f1

Browse files
committed
Fix permissions
1 parent dbd4114 commit 9de39f1

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

android/app/src/main/AndroidManifest.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,14 @@
5757
<uses-permission android:name="android.permission.INTERNET" />
5858
<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
5959
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />
60-
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
60+
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" android:maxSdkVersion="30" />
6161
<uses-permission
6262
android:name="android.permission.BLUETOOTH_SCAN"
63+
android:minSdkVersion="31"
6364
android:usesPermissionFlags="neverForLocation" />
6465
<uses-permission
65-
android:name="android.permission.BLUETOOTH_CONNECT" />
66+
android:name="android.permission.BLUETOOTH_CONNECT"
67+
android:minSdkVersion="31" />
6668

6769
<!-- USB Host feature -->
6870
<uses-feature android:name="android.hardware.usb.host" android:required="true" />

android/app/src/main/java/betaflight/configurator/protocols/ble/BetaflightBlePlugin.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,20 @@
4747
@CapacitorPlugin(
4848
name = "BetaflightBle",
4949
permissions = {
50+
// Android 12+ BLE permissions
5051
@Permission(
5152
strings = {
5253
Manifest.permission.BLUETOOTH_SCAN,
53-
Manifest.permission.BLUETOOTH_CONNECT,
54-
Manifest.permission.ACCESS_COARSE_LOCATION
54+
Manifest.permission.BLUETOOTH_CONNECT
5555
},
5656
alias = "bluetooth"
57+
),
58+
// Pre-Android 12 location-based BLE permission
59+
@Permission(
60+
strings = {
61+
Manifest.permission.ACCESS_COARSE_LOCATION
62+
},
63+
alias = "bluetoothLegacy"
5764
)
5865
}
5966
)
@@ -127,7 +134,11 @@ private boolean ensurePermissions(PluginCall call) {
127134
return true;
128135
}
129136

130-
requestPermissionForAlias("bluetooth", call, "onBlePermissionResult");
137+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
138+
requestPermissionForAlias("bluetooth", call, "onBlePermissionResult");
139+
} else {
140+
requestPermissionForAlias("bluetoothLegacy", call, "onBlePermissionResult");
141+
}
131142
return false;
132143
}
133144

0 commit comments

Comments
 (0)