i just started working on Connecting to Embedded BT Device through My Android Phone.It is connecting fine but i am facing problem when i am not disconnecting it properly. I mean first close socket and then any i/o steams opened.
But when i turn off my Bluetooth suddenly in device how will i know the bluetooth is get disconnecting. is there is any way to receive Bluetooth disconnecting listener all the time in the APP.
Any Ideas ....? Thanks
mmSocket= device.createRfcommSocketToServiceRecord(uuidToTry);
try
{
mmSocket.connect();
}
catch (IOException e)
{
mmSocket.close();
}
It's usually because the device's own Bluetooth is switched off, or isn't in pairing mode. Check the user manual to find out how to make it discoverable by turning on pairing mode. With some headphones, it's a case of holding the power button down for longer, but with other devices there's a dedicated Bluetooth button.
If you want a more reliable way to find hidden Bluetooth devices, you can use a Bluetooth checker app. These apps will scan for any hidden devices that are connected to your computer or phone. There are a lot of different Bluetooth checker apps available.
In order to enable the Bluetooth of your device, call the intent with the following Bluetooth constant ACTION_REQUEST_ENABLE. Its syntax is. Intent turnOn = new Intent(BluetoothAdapter. ACTION_REQUEST_ENABLE); startActivityForResult(turnOn, 0);
You can do it like this- Create a broadcast receiver in your code Like this:
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (!mBluetoothAdapter.isEnabled()) {
// BT is turened off.
}
else{
// BT is turened on.
}
}
}
};
and register that broadcastreceiver for following intent filter:
IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
registerReceiver(mReceiver, filter);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With