Did something change with Bluetooth Serial in Android 10? - android

I have a Google Pixel 3a XL on Android 10 that is unable to make a good Bluetooth serial connection to a Bluetooth SPP module using Bluetooth 2.0. However, I can connect to a module with Bluetooth 1.2. I haven't been able to determine if this is related to all of Android 10, or something specific to the Pixel 3 line.
I'm trying to get GPS position data from a GPS receiver via Bluetooth. When I try to bring up a connection using createInsecureRfcommSocketToServiceRecord(), the serial connection actually comes up for 1-5 seconds. I do get some data from the GPS receiver, however there are chunks missing. Then the data stops flowing. In addition to my app, I have tested this with several other Bluetooth serial terminal programs, and they all have the same results - I get some data, then it stops.
I can use this same Bluetooth module with a different Android device running Android 9 and it works great. I can also connect to this Bluetooth module from Windows and it too works fine.
I have a second Bluetooth module that is older (runs Bluetooth v1.2) and surprisingly it actually works fine with the Pixel.
Has anyone else seen issues with Serial over Bluetooth on Android 10?

Something that changed with Android 10 is that you need to have your location enabled besides the permission in order to connect to some BLE devices. I'm not sure if this will help you, but can give you some light regarding the issue you're having.
"Some telephony, Bluetooth, Wi-Fi APIs require FINE location permission
If your app targets Android 10 or higher, it must have the ACCESS_FINE_LOCATION permission in order to use several methods within the Wi-Fi, Wi-Fi Aware, or Bluetooth APIs. The following sections list the affected classes and methods."
https://developer.android.com/about/versions/10/privacy/changes

Related

How to maintain more than 7 active BLE connections on android device

I am trying to get about 50 devices to connect to my android tablet and have them actively send notification to the android tablet anytime there is something to notify.
To receive notifications I am assuming I need to maintain an active connection to the device. I also read that there is a limitation of 7 devices that can connect with an android device. Is this really true ? if true is there a workaround for me to be able to have connections to all the devices ?
Thanks
-Naveen
This is more of a hardware limitation. Most consumer phone's Bluetooth radio can only support a few devices, with most of them doing about 7, although it can go up to 12-13.
While this limits the number you can connect do for a master-slave network, you could do a scattered network with no limit, with some clients acting as bridges between different master-client networks.

Android discovering same app UUID devices

I am using bluetooth adapter to discover bluetooth devices. The search displays all devices (iOS , Android, Speakers etc) which are available in surrounding with Bluetooth turned ON.
My App sends and receive data, so installed on two different Android Devices, app can perform a chat functionality, provided both apps are using same App UUID.
Is it possible that when I perform the device discovery/search, I only limit discovery to those devices which are Android and are using my App i.e. my App UUID and not to show all other bluetooth devices.
I know this happens in iOS using characteristic UUID.
Appreciate Response.
1) First you're doing an Inquiry (search) of all nearby devices
2) for each device enumerated, do a Discovery (SDP) on it to gather all its services/profiles; If you found the one you're searchnign for, display it, otherwise forget it...
PS: I have no idea about selecting Android devices only... You can use the CoD (Class Of Device) but not sure that you can separate Android from other "smartphones"...

How to auto-pair to another Android device over Bluetooth without prompting for a pin?

I would like to automatically connect via Bluetooth one Android device into another Android device as soon as that device is in it's Bluetooth coverage zone.
Cheers
This depends on the Bluetooth version supported on both devices.
BT2.1 or below requires a pin. You can hard code the pin (as many BT peripherals, such as headsets do).
For versions greater than BT 2.1, you can use 'just works' simple pairing, which doesn't require a pin but may prompt the user to allow it.
I don't know what the Android specific API to do these are though.

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.

Android Bluetooth file transfer

I am trying to implement file transfer through bluetooth and i am using the Bluetooth -chat example that comes with the android sdk.
When i try connecting two android phones, they seem to always say, the phones are paired but not connected. This is tedious as i have tried to connect with 3 different pairs of phones and all of them say the same thing.
Is it required for the devices to be rooted or something?? How can i connect two android phones through bluetooth.
(This isn't strictly an answer, but I am yet unable to post comments.)
I've personally had good success with the Bluetooth Chat example code, and I've used it to create an application that interfaces with a Bluetooth/RS232 dongle to obtain lots of measurement data from a remote hardware device. I do confess, however, that I've only ever used the host Bluetooth code to initiate a connection to the Bluetooth SPP dongle; I've not attempted to connect to the slave code on another phone.
For reference, the two devices I've used my app on with success are my HTC Desire (2.2) and my Archos 101 (2.2). They are not rooted.
One thing that I think is worth me mentioning is that the Bluetooth Chat example appears to have a bug in the code where it accepts an array of received bytes out of the socket and presents them into the ListActivity. If lots of characters are sent from the remote device at anything much faster than typing speed, what is shown in the ListActivity on the phone shows the occasional character being corrupted. It's because (I think) the ArrayAdapter is still consuming bytes from that array to print them on the screen when the connected thread starts to fill that same array with even newer bytes. So, I had to fix that before I could use the Bluetooth Chat example code to reliably receive relatively large volumes of data from the external device.
On either the HTC Desire or Archos 101 I don't seem to have any problems with connection. I can happily have the Bluetooth connection exist reliably even over poor signal conditions (e.g. the remote device is upstairs in the house while I'm downstairs with the Android device) while my app happily polls measurement data reliably at a rate of about 250bytes a second.
Generate UUID of your phone by using adb shell, sdptool browse command

Categories

Resources