Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix not working on devices with Android 10 and above. #436

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
</config-file>

</platform>
Expand Down
20 changes: 15 additions & 5 deletions src/android/com/megster/cordova/BluetoothSerial.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public class BluetoothSerial extends CordovaPlugin {

// Android 23 requires user to explicitly grant permission for location to discover unpaired
private static final String ACCESS_COARSE_LOCATION = Manifest.permission.ACCESS_COARSE_LOCATION;
private static final String ACCESS_FINE_LOCATION = Manifest.permission.ACCESS_FINE_LOCATION;
private static final int CHECK_PERMISSIONS_REQ_CODE = 2;
private CallbackContext permissionCallback;

Expand Down Expand Up @@ -213,11 +214,20 @@ public boolean execute(String action, CordovaArgs args, CallbackContext callback

} else if (action.equals(DISCOVER_UNPAIRED)) {

if (cordova.hasPermission(ACCESS_COARSE_LOCATION)) {
discoverUnpairedDevices(callbackContext);
} else {
permissionCallback = callbackContext;
cordova.requestPermission(this, CHECK_PERMISSIONS_REQ_CODE, ACCESS_COARSE_LOCATION);
if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) {
if (cordova.hasPermission(ACCESS_FINE_LOCATION)) {
discoverUnpairedDevices(callbackContext);
} else {
permissionCallback = callbackContext;
cordova.requestPermission(this, CHECK_PERMISSIONS_REQ_CODE, ACCESS_FINE_LOCATION);
}
}else{
if (cordova.hasPermission(ACCESS_COARSE_LOCATION)) {
discoverUnpairedDevices(callbackContext);
} else {
permissionCallback = callbackContext;
cordova.requestPermission(this, CHECK_PERMISSIONS_REQ_CODE, ACCESS_COARSE_LOCATION);
}
}

} else if (action.equals(SET_DEVICE_DISCOVERED_LISTENER)) {
Expand Down