I am working on an application that connects to a device using a bluetooth socket. Everything is running smoothly on 2 different HTC handsets with Android 2.2 but I just tried a brand new Sony Xperia running on Android 2.3 and I am experiencing a really weird behavior.
When I start the application, it will scan for devices and initiate a pairing request with the device. The pairing request is received and accepted by the user, the connection is made and a socket is opened.
The problem is that as soon as the socket is closed, the pairing is "forgotten" by the phone. The device is listed as unpaired in the Bluetooth devices list, and the application must initiate a new pairing request each and every time it needs to open the connection.
Has anything changed in the way pairing is managed with android 2.3? Is there a new requirement to close the socket and avoid loosing the pairing?
Thx in advance,
Pierre
Related
I'm developing 2 Android BLE applications. One app will serve as the peripheral role and the other app will serve as the central role. On the peripheral app, there is one encrypted characteristic with PROPERTY_WRITE and PERMISSION_WRITE_ENCRYPTED.
The central app is able to connect to the peripheral and discover its services. The first time that central attempts to write to the encrypted characteristic, the system begins the bonding process and a dialog for entering the PIN appears. After the PIN is entered correctly, the characteristic can be written to successfully. If the central disconnects from the peripheral and then attempts to reconnect, a connection is briefly established but then disconnected. The onConnectionStateChange callback is received on the peripheral with a status of STATE_CONNECTED and then immediately called again with a status of STATE_DISCONNECTED.
Unless I manually unpair the devices (from the Bluetooth settings) and then start the connection process again, the central is unable to connect to the peripheral.
I've tried this solution but it did not work for me.
BLE Device Bonding Remove Automatically in Android
Both apps are running on devices with Android 5.
This issue seems to be resolved in Android 5.1.1. Originally, I was running the peripheral app on a Samsung Galaxy Tab A with Android 5.0.2. I switched to a Nexus 9 running 5.1.1 and 6.0.1 and did not encounter the issue described above.
I am implementing Bluetooth Low Energy's HID over GATT (HOGP) profile on Android Lollipop. My target is to use the phone as a keyboard/mouse, which can just plug and play with the default BLE (HID) drivers in Windows 8.1 laptop. The Android phone is supposed to act as BLE peripheral and the laptop should be in BLE central role.
Currently, I am able to establish a very short connection with the laptop. But just right after I enter the passkeys, and bonded successfully with the laptop, the BLE connection will be lost. Have anyone faced this kind of problems before? Or have any solutions on it?
Also, I failed to add generic access service to the gatt server in Android. I am curious if GAP service is included in Android BLE communication by nature? The reason I want to include this service is for defining the "device name", "appearance", and the "peripheral connection parameter update" characteristics. How I can do so?
Did you get your system fixed, I am seeing something kind of similar, where after bonding, my device will go to paired list, then about 20 sec later, the bluetooth on /off button will automatically switch to off position, wait 10 sec, then back
to on position, and my device is gone..
I'm working on my first app for a school project. It receives and proccesses data received over bluetooth (PC with terminal and bluetooth module).
Everything works as it should but if something happens that wasn't expected, the app could crash. this is not a big deal but the Bluetooth connection remains connected although my program doesn't know that and can't work. **Is there a function to request the active bluetooth connection (like restarting a socket with the adress or something?)
I cant connect it the default way because the bluetooth discvery cant find the device anymore.
If i restart the phone everything works fine again.
I'm using the default bluetooth threads from the Android develeoper website. If anyone needs to see the code I can put it here.
When you are working with BluetoothSockets you can use yourBluetoothSocket.getRemoteDevice(); This wil get the BluetoothDevice this socket is connected to.
If there is no device connected, you can hardcode the MAC-adres of the device you want to connect to.
BluetoothDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(MAC-ADDRESS);
after this you can try to reconnect.
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 have an application that needs to keep the bluetooth discovery process in a loop to always discover new bluetooth devices (when the BroadcastReceiver gets a BluetoothAdapter.ACTION_DISCOVERY_FINISHED, I just call the startDiscovery() again). I've recently added some socket communication to the app, that basically opens a Socket to a server, sends data and then closes the socket.
When I'm using 3G, everything works fine and a sniffer shows no TCP Retransmissions, the socket is cleanly opened and closed. Using Wifi, however, shows lots of TCP Retransmissions and sometimes even failures to connect the socket (with java.net.SocketException timeout).
I'm using a Samsung Galaxy S with Android 2.2.1. Is there something I'm overlooking?
Can you try to configure and move WiFi to a different channel ? If you are using WiFi also in the 2.4 GHz band interference is expected specially during initial discovery / connection, after connection it should become better as Bluetooth should frequency hop to avoid interference (unless WiFi is clogging the complete spectrum)