Termux package containing scripts to call exposed API methods in the Termux:API app. The idea behind this package is to introduce bluetooth commands in the official termux-api-package in order to call methods of a modified version of Termux:API, you can find two java classes BluetoothAPI and BluetoothLowEnergyAPI (this one under the branch dev-ble) in Termux-app-bluetooth. The repository just mentioned is a modified version of an old version of the Termux project (Termux-app-bluetooth is not official).
In order to allow bluetooth function calls I modified the shell Termux-API repository, two possible shell calls were added in scripts directory: termux-bluetooth-scaninfo and termux-bluetooth-connect (ignore termux-enable-buttons).
The command termux-bluetooth-scaninfo is used to call the functions startDiscovery and cancelDiscovery from the BluetoothAdapter java class.
The command termux-bluetooth-connect is used to call a function that has an empty implemetation (for now), you can decide what it should do by introducing your code in the function onReceiveBluetoothConnect.
A BluetoothAPI class was added in Termux:API android-java repository. Futhermore, TermuxApiReceiver class was modified in order to make the application call the functions to scan and connect.
The implementation of connect is still missing and you can also modify the behaviour of scaninfo by writing your own java code in BluetoothAPI.
In addition to the BluetoothAPI class it was introduced also another class BluetoothLowEnergyAPI. This class is under the dev-ble branch and it hasnt been merged to master due to the lack of bluetooth low enegery devices for testing.
- Clone the project in termux-app-bluetooth
- Generate your own apk from the code
- Install the apk generated
- Open the application and wait for the termux console to be installed (it downloads the binary of termux-api-package available here)
- Open Termux console by clicking on the button (check screenshots directory)
- Type termux-bluetooth-scaninfo and give the permissions
- Type termux-bluetooth-scaninfo again to start to scan bluetooth devices
- Type termux-bluetooth-scaninfo again to stop the scanning (remember to stop the scanning otherwise a broadcast receiver will stay alive) and print the results.
Usage from APK released here
- Download termux-app-bluetooth.apk
- Install the apk generated (you may need to disable PlayProtect)
- Open the application and wait for the termux console to be installed (it downloads the binary of termux-api-package available here)
- Open Termux console by clicking on the button (check screenshots directory)
- Type termux-bluetooth-scaninfo and give the permissions
- Type termux-bluetooth-scaninfo again to start to scan bluetooth devices
- Type termux-bluetooth-scaninfo again to stop the scanning (remember to stop the scanning otherwise a broadcast receiver will stay alive) and print the results.
At the moment it shows only devices name but you can add more info to be printed.
If you are getting message below probably you used a command inside termux console that required to update or install a package.
E: This installation run will require temporarily removing the essential package libandroid-support:aarch64 due to a Conflicts/Pre-Depends loop. This is often bad, but if you really want to do it, activate the APT::Force-LoopBreak option.
E: Internal Error, Could not early remove libandroid-support:aarch64 (2)
The reason of the problem can be found in Termux-Package issue 4129.
Hmm, there happens following:
- Few months ago iconv() implementation was moved from libandroid-support to libiconv. But since old libandroid-support provides libiconv.so symlink used by essential utilities (like coreutils), package libiconv can't be installed.
- Now busybox was replaced by separate packages which makes coreutils to be required for installation. So here a conflict loop starts to happen.
Thus, since the apk in Termux-app-bluetooth is based on the version 0.64 of the Termux project you must install a more recent version of it.
However, after September when I get some free time, I will try to work on a new version of Termux-app-bluetooth that supports update or installation of packages.
If you have any question (or problem) feel free to post it in Issues section or contact me at [email protected]