I am trying build a simple java program which shows battery status of connected Bluetooth devices in windows. see bellow sample image.
First I started with BlueCove and realized BlueCove only provides basic information such as address, simple name etc.. after further investigation and found out only way to read the characteristic is via BLE GATT service. therefore started writing a test code based on tinyb which was found in GitHub Bluetooth-manager project and it resulted a Exception
so far I have tried this code
import org.sputnikdev.bluetooth.URL;
import org.sputnikdev.bluetooth.manager.CharacteristicGovernor;
import org.sputnikdev.bluetooth.manager.impl.BluetoothManagerBuilder;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
public class B2 {
public static void main(String[] args) throws IOException, ExecutionException, InterruptedException {
new BluetoothManagerBuilder()
.withTinyBTransport(true)
.withBlueGigaTransport("^*.$")
.build()
.getCharacteristicGovernor(new URL("/XX:XX:XX:XX:XX:XX/F7:EC:62:B9:CF:1F/"
+ "0000180f-0000-1000-8000-00805f9b34fb/00002a19-0000-1000-8000-00805f9b34fb"), true)
.whenReady(CharacteristicGovernor::read)
.thenAccept(data -> {
System.out.println("Battery level: " + data[0]);
}).get();
}
}
Maven
<dependencies>
<dependency>
<groupId>org.sputnikdev</groupId>
<artifactId>bluetooth-manager</artifactId>
<version>1.5.3</version>
</dependency>
<dependency>
<groupId>org.sputnikdev</groupId>
<artifactId>bluetooth-manager-tinyb</artifactId>
<version>1.3.3</version>
</dependency>
</dependencies>
Exception
Exception in thread "main" java.lang.IllegalStateException: java.lang.IllegalStateException: Native libraries for TinyB transport could not be loaded.
at org.sputnikdev.bluetooth.manager.impl.BluetoothManagerBuilder.loadTinyBTransport(BluetoothManagerBuilder.java:225)
at org.sputnikdev.bluetooth.manager.impl.BluetoothManagerBuilder.build(BluetoothManagerBuilder.java:190)
at B2.main(B2.java:15)
Caused by: java.lang.IllegalStateException: Native libraries for TinyB transport could not be loaded.
at org.sputnikdev.bluetooth.manager.impl.BluetoothManagerBuilder.loadTinyBTransport(BluetoothManagerBuilder.java:218)
... 2 more
My question - > is there any other way to obtain Bluetooth device battery level using JAVA ?
Note :
- There are plenty of examples available in android and python but not for Java / windows
- Also found unanswered similar C# question
Get Bluetooth Device Battery Level