I want to know when user has connected hands free accessories and hasn't blocked calls\sms. Is it possible to know when it is connected via hardware ports or bluetooth?
Asked
Active
Viewed 351 times
1 Answers
2
Try this in your onCreate or onResume.
BluetoothAdapter myLocalAdapter = BluetoothAdapter.getDefaultAdapter();
BluetoothDevice garniture;
Set<BluetoothDevice> connectedDevices = myLocalAdapter.getBondedDevices();
for (BluetoothDevice device : connectedDevices){
String name = device.getName();
//... check for the name you want
if( name.equals("whatnameisit"){
garniture = device
}
}
if (garniture != null){
// yay we found it, lets do our work with the device here
}

petey
- 16,914
- 6
- 65
- 97
-
1and this http://stackoverflow.com/questions/6249023/detecting-whether-a-headset-is-plugged-in-or-not might help in case of wired handsfree. – sandrstar Oct 26 '12 at 12:53
-
sandrstar also has posted relevant information in his/her SO link to detect if a headset is on. here is more helpful info on android and bluetooth including permissions you need to include in the manifest: http://developer.android.com/guide/topics/connectivity/bluetooth.html – petey Oct 26 '12 at 12:57