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.
Related
I am new to using the HM-10, and I am trying to make it connect to my Android device.
With +IMME set to 0, my phone picks up the HM-10. If I connect to it through an app that I am making, a connection is successful. After connecting once, however, the HM-10 tries to connect to my phone automatically every time my phone's bluetooth is on.
I only want to start a connection via the phone, but with AT+IMME0, the HM-10 connects to the phone by itself. I thought that setting AT+IMME1 would fix this issue, but now my phone cannot find the HM-10 at all.
Am I going about this wrong? What do I need to do to get my desired outcome?
AT+IMME1 put the HM10 in manual mode, meaning the bluetooth radio is not turned on until it receives AT+START, AT+DISC?, AT+DISI? or AT+DISA over serial.
Here's the relevant section in the datasheet
We are building an Android App which will let it connect to other android devices via a Socket Connection through a Wifi Hotspot created in the Server Android Device.
For most of the cases, this works perfectly. However for some cases, no matter how many times we try, a device is not able to connect to a WiFi Hotspot. This issue is not device specific. A device which is able to connect now, may not be able to connect at some other time.
While we were desperately looking for workarounds, we realized that if we Switch on and off the Hotspot in the connector, then it connects immediately to a WiFi Hotspot it was not able to connect previously.
Can anyone help us understand why is this happening? Also, is there anyway we can replicate this without switching off the WiFi Radio(switching on the Hotspot switches the Radio off)?
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 want to create a connection between my Android and a PC (or another device) just like in the Bluetooth menu from settings.
I have manage to get the list of all bt devices in my range and get their MAC addresses.
So, I have the BluetoothDevice, how can i connect to it or pair with it? I saw a lot of stuff about creating a server on PC, but I don't want that, i just wanna connect with the device.
My attempt were to get the UUID of the device and use createRfcommSocketToServiceRecord...but when i try socket.connect() it cannot connect (because I don't have a server). So practically I need to make the same structure that the OS is doing (connect with the device, if the connected device is trying to send i can receive the info and so on).
If I managed to connect with the device, I want to listen all that it is emitting, no matter the data...I haven't researched this topic, but any advice will be nice.
The connection must be made with any device that supports bluetooth, and I don't have access to it (of course the device is giving me the permission to connect).
Grab the Android sample projects by doing this http://developer.android.com/tools/samples/index.html
They have an app called BluetoothChat that pretty much does just what you want.
The thing about the 'server' is just in the connection, one side needs to open a listening port and that side is arbitrarily the 'server'. Once they are connected they are merely peers and you can write/read data till the cows come home.
I develop app which contains a client and a server side, so I need to test work between them. I have a real android device and I want android device to connects to emulator. I'm working at work sometimes(if I have free time of course) and at home. I have the WiFi router at home and I can connect to the real device by emulator(TCP listener running on the real device), but not vise versa(I don't know which exactly IP to use). But at work I have only hot-spot WiFi point without router. My android device connects to it fine. Even more ADB can connect to the device when adbWireless running on it. But it doesn't work, I can't connect to tcp listener in any cases. The difference between home and work is existence of WiFi router. Are there any solutions? If not why Android debug bridge(ADB) can connect to adbWireless? Thanks.
I solved the problem. I run tethering on my real device and run the server on it. Then I use a program Connection state viewer there is a link: https://play.google.com/store/apps/details?id=ru.nolesh.android.connectionstateviewer It helps me to find IP address. After that I start the emulator and the client side on it. So I connect to my server by given IP.