Sometime bluetooth is enabled but no any device connected. I want to know how to determine no device connected to bluetooth. The following is example.
1. Headset disconnected.
2. No file transfer.
Probably, You can just call getBondedDevices() it will give You all connected devices.
However, I think You might actually need to know not only connected (paired) devices, but if there's any active connection with one of them. Unfortunately (and this question seems to confirm it) there's no way to find it out afaik.
Related
I was doing some research and wanted to know if it's possible to handle calls of my phone from a device (smart watch, bluetooth headset) that is connected to my phone via bluetooth.
I intend it be able to answer calls that come to phone and make calls from my phone when I give the command to the device and I want that device to act like the bluetooth speaker during the call.
I've seen use cases where it is done but have no idea on how it's done or where to start, Any ideas on this? :)
What you are looking for is smartwatch with a speaker/microphone. You should be able to find plenty of them on internet.
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.
What I want to know:
I'm wondering how the android system (like Android smart phone) auto-connects to devices which is paired before.
For example, I pair my bluetooth headset with my android smartphone in the procedure of "turn on scanning/advertising -> click pairing" on day 1. And when I turn on advertising on my headset, it connects automatically on day 2, 3, 4, and so on. The point is, I don't have to make my smartphone scan again to find my (paired) headset.
I can't understand how android system finds that the paired device is turned on. Does the android system scan periodically in background? Even if I don't click "scan" button?
Why I ask:
I want to make my app autoconnect to customized BLE device, after make pairing. I succeed to make pairing(bonding) with createBond() method, but after that, I couldn't find how to make autoconnect. I know I can turn on autoconnect function like this way, connectGatt(XXX, true, XXX), but this autoconnect function doesn't work when the BLE device is disconnected a few days.
So I want to make my app works like android system and Bluetooth headset. But I couldn't find how android bluetooth system works even I dig AOSP codes.
I found many questions (here and here) about problems like mine but there were no answers.
Thanks in advance.
Update:
I found that bt_btif gets activated (with LG smartphone and Nexus 5) when the paired headset is turned on (start advertising). But bt_btif doesn't get activated with my custom BLE device... What can I do?
Executing connectGatt(XXX, true, XXX) is the correct way to go. gatt.connect() also starts an auto connect. Once you execute that, your phone will scan for the device and once it appears it connects to it. The only thing that interrupt this call is either if Bluetooth is turned off on the phone or if your app process is being killed. To avoid your process from being killed, let your app have a foreground service.
One gotcha however, there is a bug in Android which will sometimes make auto connect do a direct connect instead (and cancel after 30 seconds or so). See https://code.google.com/p/android/issues/detail?id=69834. You need to use reflection to avoid this bug.
I think I found a solution.
First, the solution for my question: Android smartphone seems to detect state changes of nearby bluetooth devices from the hardware sides. When the paired bluetooth headset starts to advertise, a callback in HAL (I think) is called.
So I made my app to connectGatt with autoConnection=True to the device that I want, by using MAC address, when the activity is started (in onResume() of MainActivity).
The connection would fail if my BLE peripheral device is not advertising. But the device auto-connects when it starts advertising, because the autoConnection parameter was set to true.
I've done a similar app and i didn't have problem with that. As a last resort for your problem, i would suggest writing the BLE Device Address in a simple DB table and manually connect to it. I've made something like this here
. It is no best practice code, but i hope you can find ideas for you solution.
I have a question concerning WiFi scanning and AccessPoint mode on Android.
The first thing I noticed when playing around with setting up an access point is that WiFi "turns off" (clearly, WiFi must be turned on in some way, but I guess "off" refers to the fact that we cannot connect to another access point).
My question is: why can't I scan for access points on Android while in access point mode? Apparently, it has nothing to do with the WiFi standard because it works on my Ubuntu laptop - when I activate hotspot mode and create a hotspot with another device after that, I can still scan and see the new access point.
To be more specific: If WifiManager.isWifiEnabled() is true, WifiManager.startScan() returns true and will deliver scan results. However, if my phone acts as an access point, isWifiEnabled() returns false and so does startScan(). I would love to see available access points while in hotspot mode.
I don't see why it shouldn't be possible for a WiFi chipset to scan for access points while acting as an access point and I would be grateful for some clarification.
Thank you very much,
Micha.
Have you tried doing a WifiManager.startScan(), and does it return false? It's not clear that you have.
As far as your question is concerned, I don't know the answer. But I do know that not every WiFi chipset supports both scanning while also being an access point for other devices. Maybe it's easier to just disable the functionality in software rather than have to know if the chipset supports it (this is assuming that the functionality really is not there, I guess we'll find out when you try it!)
My task is, to detect android devices, when reaching the propximity of some BT-Scanners(My PC)
Instead of discovering all visible devices:
all Device BT MAC-Adresses are stored at my PC
Can i look for special devices with the given MAC-adress without turning on discoverability on the android device? I don't want to turn on the discoverability all the time, so maybe I can check with the special MAC-adress for devices. Like the "ping" function in network technik?
I hope you understand my problem and hope for solutions.
If it is just one (or a few) device , the quickest approach is to try to do a connect to it to determine if it is available.