Closed Avani-A-S closed 1 year ago
Have you granted the location permission to your app in the device's settings and set up your manifest according to the android docs?
after a quick look i think this might be related to your permission setup or the timing. as stated before the permission should be set up like on the android docs, but your manifest is using the legacy and current used permissions. if you target sdk 31, you should either remove legacy or tag them via the attribute to remove them. if your code has nothing todo with the location you should also remove this permission. in my experience this behaviour is also influenced by the device itself. Still a last thing, if the device is not very performant on some (expected as you also target sdk23) the permissions take time to be granted. await the result before scanning.
I tried by removing legacy and location permissions. Keeping BLUETOOTH_CONNECT, SCAN and ADVERTISE only. Still the same results. Devices are scanned and listed fine. On selecting the device, I am calling the scan method again, matching the name of peripheral and sending connection request. Does not seem like timing issue.
I have debug further and observed that the exception occurs for profile in BluetoothAdapter.java. I am not sure if the issue is due to the device I am trying to connect? I am working for connecting to Mi Band 3.
if (profiles != ACTIVE_DEVICE_AUDIO && profiles != ACTIVE_DEVICE_PHONE_CALL && profiles != ACTIVE_DEVICE_ALL)
Observed a discrepancy in Peripheral.class and Peripheral.java file. In original source code future is retuned outside of synchronized scope whereas in converted byte code it is retuned inside synchronized scope. Is it usual?
droidplug\java\src\main\java\com\nonpolynomial\btleplug\android\impl\Peripheral.java
public Future<Void> connect() {
SimpleFuture<Void> future = new SimpleFuture<>();
synchronized (this) {
this.queueCommand(() -> {
...
});
}
return future;
}
.gradle\caches\transforms-3\54aadb977e195212821f046c57abb043\transformed\droidplug-debug\jars\classes.jar!\com\nonpolynomial\btleplug\android\impl\Peripheral.class
public Future<Void> connect() {
SimpleFuture<Void> future = new SimpleFuture<>();
synchronized (this) {
this.queueCommand(() -> {
...
});
return future;
}
}
Despite of previously mentioned exceptions, my app is crashing with A Fatal signal 6 (SIGABRT)
while executing return future;
I have followed these steps for droidplug set up https://github.com/deviceplug/btleplug/issues/287#issuecomment-1367914182
I have tried rebuilding droidplug-release.aar after cleaning as well. But return statement stays inside synchronized scope. Can it be the issue for connection failure.
Check out https://github.com/deviceplug/jni-utils-rs, class cache branch and add it as local dependency resolved the issue with future.
Describe the bug Failed to connect BLE Device on android.
Expected behavior Should connect to BLE device from Android App. With same code able to connect with same BLE device from Windows console app.
Actual behavior Catching Security Exception in
connect()
inPeripheral.java
indroidplug
. Debugged and observed thatthis.gatt
initialized successfully. Not sure why throwing exception. Not able to seevar4
value.Code available at https://github.com/Avani-A-S/bledemoapp
Additional context Log