Here are the steps needed to connect to the Milicom BLE PTT button and receive notifications.
- Import the MilicomBLE module into your Android Studio project.
– File – New – Import Module
- Add the dependency for the new module.
– In the build.grade where you want to use the module you will need to add compile project(‘:milicomble’)
- Add these two lines to the file where you would like to call the MilicomBLE module to import the files needed.
- Create a MilicomBluetoothService object.
- Implement the MilicomBluetoothListener interface and all of the methods within MilicomBluetoothListener. This can be done in a new class or in the activity where you need the MilicomBluetoothService.
– New Class Way
– In the activity where you need the MilicomBluetoothService
- Initialize the MilicomBluetoothService by passing it a context as the first parameter and a MilicomBluetoothListener object as the second parameter.
- No filters are needed, but you can add any number of name filters and mac address filters to the MilicomBluetoothService that it will filter by when it searches for BLE devices. The name of the BLE device that it is searching for will have to contain all of the substrings that you add using bluetoothService.
AddNameFilter(), and as long as the BLE device that you are searching for is one of the MAC address filters that you added, it will get found. You can add the filters like so.
- After you add all of your filters, you will then be able to search for any devices in the area.
- Found devices will be returned in the onDeviceFound(BluetoothDevice _btDeevice) callback function within the MilicomBluetoothListener object. This could return duplicates so make sure you handle that.
- You can then connect to a device by calling blueoothService.
ConnectToDevice( BluetoothDevice _deviceToConnectTo); and passing it the device that you want to connect to.
- You can also disconnect from any currently connected device by calling bluetoothService.
- Notifications will be returned through the onCharacteristicNotificati
on(final BluetoothGattCharacteristic _characteristic) callback function within the MilicomBluetoothListener object. In the case of this specific MilicomPTT button, the object is a string in memory. So when you get the object back you will have to get the string value of it. Like below.
The UUIDs for the UART characteristics are in the MilicomBluetoothGattCallback.
java file, I think these are a standard and will be the same regardless of the device.
To download the Android Studio API/module, and the MainActivity.java file on this page:
Enter your name and email address here. You will receive an email including the download link.