Android - Bluetooth device connected

I want the broadcast receiver to listen on BT devices. Can someone tell me which broadcast I need to listen to? I tried android.bluetooth.device.action.ACL_CONNECTED , but it does not work.

Thanks.

0
source share
2 answers

You can pull out the device using the following in your BroadcastReceiver.onReceive() function:

 BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); 
0
source

If you are looking for whether the device is a โ€œconnectionโ€ then you need the android.bluetooth.adapter.action.CONNECTION_STATE_CHANGED file

However, this does not start when the device is STATE_CONNECTED. So I did when the state connects to send the broadcast in a few seconds.

  if (bluetoothAdapter .getProfileConnectionState(BluetoothProfile.HEADSET) == BluetoothProfile.STATE_CONNECTING || bluetoothAdapter .getProfileConnectionState(BluetoothProfile.A2DP) == BluetoothProfile.STATE_CONNECTING) { final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { if (bluetoothAdapter .getProfileConnectionState(BluetoothProfile.HEADSET) != BluetoothProfile.STATE_CONNECTING || bluetoothAdapter .getProfileConnectionState(BluetoothProfile.A2DP) != BluetoothProfile.STATE_CONNECTING) { context.sendBroadcast(new Intent( BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)); } } }, 2000); 

Kind of hacks, so I posted this issue in the Android tracker. http://code.google.com/p/android/issues/detail?id=25957

0
source

All Articles