Remove a Connected Node on Android Wear programmatically - android

On Android wear, the NodeAPi has interfaces to fetch the connected node. This connected node is maintained by the OS itself somewhere (guessing it is in gms.wearable shared preferences). Because of this reason, when one tries to switch a connected device of the watch to another one, Android Wear 4.4W2 prevents this switch.
is there a way to remove the connected node on wear side programmatically?
addListener(GoogleApiClient client, NodeApi.NodeListener listener)
getConnectedNodes(GoogleApiClient client)
getLocalNode(GoogleApiClient client)
removeListener(GoogleApiClient client, NodeApi.NodeListener listener)
Above is the list of NodeAPIs from Android wear documentation. From my analysis, I just think they are either missing the API to removeConnectedNode or they simply want to hang on to the 1st connected node after factory reset.. The latter seems bad design and currently seems to be the case with Android 4.4W2 update.

I don't know for 4.4W2 since there's now an option to dissociate connected devices, but as far as 4.4W1, you could not associate your Wear device with more than 1 handlheld device per factory reset, ie if you want to disconnect your watch from your companion handheld, apart from turning off the Bluetooth connection from the handheld (if you just want to interrupt the communication) or manually resetting your watch, you can't dissociate the devices.
EDIT
Just tested the dissociate option. Doesn't do anything on my Samsung Gear Live except starting an activity saying "Dissociate the devices". So I guess that what was true on 4.4W1 is still true for 4.4W2

Related

HM-10 as BLE Listener: setting up a brief connection from it

I need to estabilish a brief communication between a BLE master and a BLE peripherical device.
Until I have to use the mobile phone I have no problems, since I select the bluetooth device from Android, I can connect to it and then I can receive data simply writing them to HM-10.
BUT, this approach is battery expensive, since the BLE scanning is more battery expensive than the BLE advertising (right?). So I want that the mobile becames an advertisor and the HM-10 takes the ROLE of Slave.
BUT, I still don't understand if it is possible to connect to other devices: I tried AT+CONN and it always fails (AT+CONF). Is there any way to send brief data from the HM-10 to the advertisor, even without connecting?
Even my firmware looks slightly different from the readme! For example,AT+LN is present in the documentation but it appears to not exist. Does a better version of the firmware for this device exist, or, are sources available somewhere? I installed the HM-Soft V705 (lastest).
Thanks
UPDATE 1:
#ChrisStratton Ok, I have some intresting news: I was already following your idea (phone advertise sometimes, while HM-10 always scan and tries to connect to the service if it sees it, then HM-10 send some data, phone answer). I managed to make the phone visible from HM-10 (don't ask me how!). I am using the BLE Tool Android app to test everything. Now, the central problem now is that HM-10 won't connect to the android service even if the advertisor is connectable (see attached images).
I am sospicious that the AT+CO (that I discovered is a kind a replacement of AT+LN, but I am not sure) can help, but i don't know how.

Android: Using HID over GATT directly in Application (Gadget=HID → control Application)

I have a Bluetooth LE Joystick with a couple of buttons. I want to connect it directly to the app without using the Bluetooth Settings, but by connecting to it via BluetoothLeScanner.
I already can connect to a Heart Rate Monitor and get periodic notifications of the HR-values.
I also have created a little temperature/light/humidity sensor with an ESP32 to which I can also connnect and display the sensor values in the app.
My understanding of this HID device may be erroneous. With the help of the App BLE Scanner I can connect to this gadget via BLE and see the offered services.
One of them is 0x1812 HUMAN INTERFACE DEVICE, which contains a couple of characteristics of type REPORT, among others which are described HID OVER GATT PROFILE SPECIFICATION (HOGP_SPEC)
How can I find out which button got pressed, what position the joystick has been moved to? I guess that this has to occur via notifications to which I have to subscribe to.
Is there any Android library avaliable to handle HID input devices? What I do NOT want to do is to use the Bluetooth settings and connect to the device and have it become detected as a HID device and replace the keyboard with some odd mapping. I don't want the OS to get involved at all, just like when I connect and use the HRM and the ESP32.
I couldn't find any information on this.
I can connect to the device with my app, enumerate the services and characteristics. But from there on, I have no clue how to work with HID. Ideally I'd get notifications like "Button A has been pressed" "Joystick got moved to x=32" where x would range from -127 to 127, for example.
Accessing the HID characteristics requires the BLUETOOTH_PRIVILEGED permission since Android 5.0. The only way for an app to obtain that permission is to be signed with the same certificates as system apps.
This is a security feature, to prevent an app from receiving HID events from your keyboard and stealing your passwords.
Quoting from https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/BLE_5F00_on_5F00_Android_5F00_v1.0.1.pdf
4.6 Protected services
Android does not allow to read or write data to the following characteristics (and their descriptors):
HID Service (since Android 5):
a. HID Information
b. Report Map
c. HID Control Point
d. Report
FIDO (https://fidoalliance.org/) (since Android 6)
a. U2F (0000FFFD-0000-1000-8000-00805F9B34FB)
Only applications with BLUETOOTH_PRIVILEGED, that is, applications signed
with the same certificate as the system, are able to read and write
data to those characteristics.

Manually pairing Bluetooth Decives in Android?

I was reading this
http://developer.android.com/guide/topics/wireless/bluetooth.html#QueryingPairedDevices
which is allot of help on how to pair,connect to a bluetooth device.
I have a situation where I have several BT devices that are in Non-Discover mode always. I know the MAC and the PIN of these devices. IS there a way in Android Dev to manually add devices to the PAIRED list so i can just use the connect as a client.
I understand this maual is written allot for V3. i think i will need to do this on 2.0 ; 2.1- has anybody done this before?
Basically these devices I want to connect to are power saving modules I used pre built BT modules to monitor daylight, another one humidity, etc.. every 3hrs or when interrupted and runs of a single battery for months. So turning off divcory on server saves immense power and prevents other people trying to connect and waste battery.
Not sure what you mean by "manually": Do you mean "manually" as in GUI/user interaction, or "manually" as "I do it in my own application code"?
Some suggestions though:
If you can make your BT devices discoverable at all, you could do it this way:
Make your BT device discoverable
Let Android search for and find the device and then initiate a connection
Android will ask for the PIN for pairing with the device; enter the PIN.
Once pairing was successful, Android stores the pairing information for future use, so that you can
Make your BT device invisible again.
From then on your app should be able to connect to the BT device at any time without further pairing operations.
If the said is not an option for you, maybe you want to go another way:
In current Android versions there are different API routines implemented which are neither documented nor exposed in the normal SDK. A hack kind of solution may be to use some of these "hidden" ("#hide"...) APIs, either via reflection or via modification of your SDK installation.
But be aware that this is always a hack and it may work on a specific device with a specific version of Android and is likely to break your app on another device and/or any other Android version.
Having said that, here comes some reference:
Example of how to access "hidden" bluetooth API.
Then, have a look at the source code for android.bluetooth.BluetoothDevice, e.g. here.
In there, public boolean createBond(){...} may do what you want.

low level bluetooth broadcast

Since bluetooth is a broadcast protocol, is there some way to listen for broadcasts while not discoverable? The idea is to avoid making a device discoverable, and simply listen for broadcasts, check the devices for a particular device name, and then connecting to that device's mac address (followed by handshaking, verification, etc).
Specifically, I have a bluetooth device that uses the AT command set (user manual here), and I want my Android device to autoconnect to it when it gets into range. However, I want a solution that doesn't require my Android to be discoverable all the time, because I expect the Android to not be in range most of the time.
Is there a low-level bluetooth command that I can send from my first device, and listen for using the Android SDK that doesn't require pairing, connecting, or discoverability? Something like and ACL request, perhaps?
(Additionally, my reasons for not making my device discoverable are mainly power, and also slightly user privacy reasons. How significant is the battery drain of device discoverability? Next to nothing? Significant?)
Its called a Bluetooth PAGE command. Not sure how you'd use it from your device though, but it allows a Bluetooth device to (in effect) announce its presence to its configured master. You'd have to look up the Android response to a PAGE to see how well that's supported though.
If the Android is connecting to the device, then the Android never needs to be discoverable. Unless I'm misunderstanding... (The radio on the Android just needs to be powered-up and not "connectable" nor "discoverable")
The Android can just try to connect every so often (sending a PAGE), to see if the remote device has come back into range. Then even the remote device doesn't need to be discoverable, just 'connectable' -- assuming your Android program remembers the remote device's device address.
Or you could have the remote device try to reconnect ot the Android device every so often (presuming the remote device supports making connections). You would need to have the program on the Android be a server/listener, and the Android Bluetooth in 'connectable' mode.

Android Bluetooth - How to initiate Pairing

I want to initiate a pairing request (not connection at this point of time) to a non android device. This can be found working on Settings Application > Network > Bluetooth Settings > Click on a device after scan. A pop up appears on both the devices with a 6 digit pin.
As per Android's documentation this should have popped up in my application as well, if I do something like this
device.createRfcommSocketToServiceRecord(MY_UUID);
As per Android's API documentation
"Once a connection is made with a
remote device for the first time, a
pairing request is automatically
presented to the user."
And it is also mentioned that
"The current Android Bluetooth API's
require devices to be paired before an
RFCOMM connection can be established.
(Pairing is automatically performed
when you initiate an encrypted
connection with the Bluetooth APIs.)"
Even when I used the sample Bluetooth Chat application (only to test if it initiates a pairing on first connection) it didn't worked.
I also tried using a generic UDID like "00001101-0000-1000-8000-00805F9B34FB" but to no avail.
Couldn't find the source code of Settings Application (Android OS 2.1) to figure out myself. The sources available in Android GIT were for Android 2.3
Even if you cannot answer the question, only pointing out to Android Packages Settings App sources for Android 2.1 might do the trick for me.
It works for me with this UUID : "00001101-0000-1000-8000-00805F9B34FB".
The intent for pairing request is launched when you call socket.connect() if I remember correctly.

Categories

Resources