Update 1
SelectDeviceActivity.java – includePairedDevices Function
Originally, the includePairedDevices
function was designed to loop through all available paired Bluetooth devices and simply display them on the user interface. This meant that every paired device—regardless of whether it supported the functionality our app required—was shown to the user.
We have now replaced that logic with a more refined approach. The new version of the function does the following:
Connects to Each Paired Device:
Instead of merely listing the devices, the function actively attempts to connect to each paired device. This is important because it allows the app to interact with the device and verify its capabilities.Checks for a Specific UUID:
Once a connection is established, the function checks if the discovered device’s Universal Unique Identifier (UUID) matches a predefined UUID that is hardcoded in our application. The UUID is used to identify a specific Bluetooth Low Energy (BLE) service that our app requires.Why This Matters:
This ensures that only devices capable of handling our expected BLE service are included in the list. It filters out any devices that do not support the required functionality, making the user interface cleaner and the overall process more efficient.
In summary, the updated function not only looks for all paired devices but actively verifies that each device is compatible with our app’s requirements. This leads to a more reliable and user-friendly experience.
BLEService.java – Command Delays Adjustments
In our BLE communication, timing is crucial for ensuring that commands are sent and processed smoothly. Two key constants were modified in the BLEService.java
file:
COMMAND_DELAY:
Old Value: 200 milliseconds
New Value: 100 milliseconds
Impact:
Reducing this delay means that after sending one command, the app will wait only 100 milliseconds before sending the next command. This decreases the overall latency and makes the system feel more responsive. Faster command processing is especially important in interactive applications where timing (like LED animations) is critical.
COMMAND_12_DELAY:
Old Value: 150 milliseconds
New Value: 100 milliseconds
Impact:
This constant controls the delay for sending an indicator command for brightness adjustments. By reducing it from 150 to 100 milliseconds, the brightness changes are communicated more quickly, which helps create a smoother and more immediate user experience.
By reducing these delays, we’re improving the responsiveness of the Bluetooth communication. In practical terms, the app will react faster to user inputs because there is less waiting time between sending commands. This is a common performance improvement technique, where fine-tuning timing parameters can lead to a more fluid and enjoyable experience.
Additional Changes
Manifest.xml:
We added the following permission:<uses-permission android:name=\"android.permission.POST_NOTIFICATIONS\"/>
This permission is required for higher API levels to properly display notifications on the phone.
MainActivity.java:
We also implemented a check for the POST_NOTIFICATIONS permission at app startup and request it if necessary.
You can visually see these changes on our GitHub under the commit titled "Fixed permissions for API 33+."