I am trying to use Bluetooth SPP to communicate over it. In some Android phones, SPP profile is not activated. I faced the problem in the application that SPP was not activated and so the connection could not be established over bluetooth and when I started another app that is 3g hotspot which I think activates SPP and I was able to connect over bluetooth in my app.
So, how can we actually activate SPP profile of bluetooth in Android devices? And does all the android devices has SPP profile?
In developer.android.com BluetoothSocket:
The most common type of Bluetooth
socket is RFCOMM, which is the type
supported by the Android APIs. RFCOMM
is a connection-oriented, streaming
transport over Bluetooth. It is also
known as the Serial Port Profile
(SPP).
This might answer your question ..
https://source.android.com/devices/bluetooth/services
SPP (or ability to use Java API's to establish RFCOMM channels) is available from Android (2.0/2.1) release (Eclair) onwards
On the Android phone you will probably need to run an application that initiates the service over SPP.
**
public BluetoothServerSocket
listenUsingRfcommWithServiceRecord
(String name, UUID uuid)
** API can be used to create a service with specified UUID to listen,
Doing this should make this service visible to other devices which can then connect to it.
I just called Samsung help regarding bluetooth SPP on an S8+ phone. They tell me wait for Android Oreo as it isn't available till then. My previous Sony Xperia used Ntrip Client to talk to an external Geneq GPS to receive corrected coordinates and worked really well. Seems we went backwards somewhere?
Ntrip client on the phone collects an internet data stream of GPS corrections every five seconds and sends these to the GPS. The GPS uses the corrections and sends back adjusted coordinates to the phone to use in any application.
I would appreciate someone brighter than me pointing out a quick fix I just load and run to bring back this functionality.
Related
I have a setup with two Android devices: an android phone and a custom hardware running Android 10. The latter acts as a BLE Server, which is discoverable always with the same static MAC address. Also when that custom HW is paired with the phone it has access to phone's contacts and calls history. That HW can also play media (sound) streamed from the phone.
I use RxAndroidBle 1.11.0 library for BLE communication. As soon as I exchange some data via BLE Characteristic I unsubscribe from the RX observable so the library effectively calls: bluetoothGatt.disconnect() then blutetoohGatt.close()
(all those inside the DisconnectOperation class).
My problem is the fact that based on my observations, calling blutetoohGatt.disconnect() disconnects the classic BT profile (PBAP) as well.
Is it an expected behaviour?
I have investigated the code of generic Android P framework and it looks that calling bluetoothGatt.disconnect() -> bluetoothGatt.close() completely disconnects the device described by the given MAC Address:
BluteoothGatt#disconnect()
BlutetoothGatt#close()
BlutetoothGatt#unregisterApp()
I would risk a statement that I have quite unusual BLE use-case scenario where the phone (Central/Client) and the peripheral (custom Android HW/Server) are connected simultaneously via Classic BT profile and via BLE.
I suspect that disconnecting/closing device using its BT MAC address disconnect both profiles, hence the contacts sharing stops working.
Is it possible to disconnect BLE connection only, but not affect the classic BT (SPP/PBAP) connections between the two devices?
After further investigation described on that Github issue
I realised that my custom hardware is equipped with dual-mode BT adapter so it supports classic BT (BR/EDR) and the BLE one.
As soon as I pair an Android phone with the custom hardware via System Settings, classic BT profiles are bonded, but also my GATT Server advertises relevant services using the same MAC address which is used by the BR/EDR. Disconnecting BLE client connection disconnect BD/EDR as well.
What helps in my case is to not start pairing via System Settings, but let the GATT server advertise and let my BLE client app to connect (and trigger pairing) first. As a result I have a BLE connection with server available under "AA:AA:AA:AA:xx", while the classic BT profiles are connected to "BB:BB:BB:BB:yy" interface on the custom hardware.
Now, disconnecting BLE profile does not disconnect the classic one.
I am looking for a solution which would allow my GATT Server to be advertised with BLE only, but no luck so far.
Here are some interesting links I have found:
connectGatt creates connection over BT Classic instead of BLE
how to force BLE "just works" pairing in Android
BLE Dual-Mode
I am creating an application for communicating Android mobile devices with Bluetooth beacons. I have successfully achieved this between one beacon (which acts as a client) and one android mobile device (acts as the server, listening for the connection). Please find the code snippet below,
Client app
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(MACaddress);
BluetoothSocket socket = device.createInsecureRfcommSocketToServiceRecord(UUID.fromString("f3c74f47-1d38-49ed-8bbc-0369b3eb277c"));
mBluetoothAdapter.cancelDiscovery();
socket.connect();
Server app
mmServerSocket = mBluetoothAdapter.listenUsingInsecureRfcommWithServiceRecord("NAME", UUID.fromString("f3c74f47-1d38-49ed-8bbc-0369b3eb277c"));
socket = mmServerSocket.accept();
This works fine with one mobile device (server) where I am able to obtain its MACaddress by scanning nearby Bluetooth devices. But consider the case when there are around 20-25 mobile devices present in range - scanning would consume so much time. I would like to do this without performing a scan.
Is there a way to achieve this without using the server's MACaddress? Can the connection be established with the unique UUID alone? Please note that I do not want to pair the devices.
Any other solution in this regard is also welcome. Thanks!
You can't create a socket connection to a bluetooth device without identifying the bluetooth device itself, and the unique identifier for bluetooth device is a MAC Address. Even if there were an Android API that would allow you to do this via UUID alone, the underlying implementation would still have to search for nearby devices (e.g. scan) and find one that is accepting socket connections using the UUID. So the scanning mentioned in the question would still have to happen.
Yes, scanning can use a bit of power and CPU intensive if a number of bluetooth devices are around. You can limit this two ways:
Only scan briefly. For your use case, it seems you could just scan for a few seconds then stop once you find a supporting device. This should not be too resource intensive.
Use scan filters on Android 5.0+ to match only the devices that you are interested in.
I am a little confused on how to build this android app. Here's how it should work. I have a list of paired bluetooth devices. Lets say paired devices are:
1. A bluetooth head set.
2. A mobile phone.
And my app should automatically connect only to my headset when ever it comes in range.
Thats the basic functionality. I have been doing some research on bluetooth technology and its implementation. I came across the bluetooth chat application, when I started using the application I realized that both phones should have the app on it in order to connect and exchange messages. I tried connecting to my headset but it doesnt connect. And also when I removed the bluetooth chat app from one of my device and tried to connect it from a device which had bluetooth chat app, the devices couldnt connect.
If you have already worked on bluetooth this might look very simple. But how can I connect to a bluetooth device from my app when ever its in range even if the other device doesnt have my app.
Thanks.
This will be a 2 sections answer:
-To connect to a Bluetooth Headset, check my answer on here
-To Always connect to that device, you can save device address to memory then create a service with BroadCastReciever that listens for Bluetooth Connectivity. and check which device gets connected and compare it address to the one save in memory once its finds it connected call ibth.connect(device). ibth is inside the above link.
I'am trying to make an app that receives some binary data from a other device which is not running android. The Android phone should not transfer any data to this device. So over to my questions:
Should the phone act as the server which establishes the RCOMM channel?
Is it possible to connect the phone and this device without paring, as long as I know the MAC-address of the device? If so, how?
And yes, I have read http://developer.android.com/guide/topics/connectivity/bluetooth.html so no need to only answer with that link. :)
Thanks in advance!
1)
Phone should act as a receiver.
I found that the tricky part is to use correct UUID.
If you connect two phones you should be generating those and everything work fine, but on your hardware you can't change UUID that easily.
Take a look at these reserved UUIDs.
For a Serial Port Profile's (SPP) communication use UUID 00001101-0000-1000-8000-00805F9B34FB.
2)
You can connect to a device without pairing if you already know the MAC address, you don't even need to use BlueTooth discovery.
To get device using MAC address call getRemoteDevice(String)
and then createRfcommSocketToServiceRecord(UUID) to get BlueToothSocket.
Also take a look at checkBluetoothAddress(String) to validate MAC address.
I am trying to get an android phone to look like a bluetooth GPS unit so that a PC or any other device that supports bluetooth GPS can use it. I figured out the whole NMEA thing and have the device spitting out correct NMEA sentences. My problem lies in the bluetooth area though.
I have a bluetooth thread setup for listening for a connection. In windows I can see the service "Bluetooth GPS" that I created. The problem is I can't figure out how to get windows to open up the connection so I can start sending the NMEA sentences. When I enable the service in windows it says "Bluetooth Peripheral Device" and there are no drivers available.
What am I missing that would allow windows to understand that I want to communicate over RFCOMM and the device is a GPS device?
You need atleast Android 2.0 because unfortunately older versions of Android's Bluetooth API does not support RFCOMM yet neither does it support other methods of communicating its GPS data to an other Bluetooth device such as a windows PC.
Depending on the phone you are currently using you may be able to update it to Android 2.0.
I just tried it with my phone and it only supports Bluetooth headset and A2DP stereo audio.
You would have to create an app for android that passes your GPS data over Bluetooth RFCOMM just like the Bluetooth wireless tether app. You have to have the app running and then pair the device to your PC in order to use its services.