Is there a way to autoconnect my phone to an paired device without having to activate bluetooth every time? I want to create an app that works in the background and connect to a paired device even if the bluetooth is off.
if(device.getBondState()==device.BOND_BONDED){
Log.d(TAG,device.getName());
//BluetoothSocket mSocket=null;
try {
mSocket = device.createInsecureRfcommSocketToServiceRecord(MY_UUID);
} catch (IOException e1) {
// TODO Auto-generated catch block
Log.d(TAG,"socket not created");
e1.printStackTrace();
}
try{
mSocket.connect();
}
catch(IOException e){
try {
mSocket.close();
Log.d(TAG,"Cannot connect");
} catch (IOException e1) {
Log.d(TAG,"Socket not closed");
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
This code connects the device to a already paired device but the user needs to turn on the bluetooth every time to use my app. I need to know if there is a way to listen if the device that I'm paired to is present and connect to it without turning on the bluetooth every time?