I am trying to listen to the bluetooth connection/disconnection events to determine if there is a bluetooth device connected. I'm trying to do it this way so that my app will run on older android versions.
I registered the receiver in the manifest as such:
<receiver
android:name=".BluetoothReceiver">
<intent-filter>
<action android:name="android.bluetooth.device.action.ACL_CONNECTED" />
</intent-filter>
</receiver>
And in my BluetoothReceiver class I have
public class BluetoothReceiver extends BroadcastReceiver{
public final static String TAG = "BluetoothReciever";
public void onReceive(Context context, Intent intent)
{
Log.d(TAG, "Bluetooth Intent Recieved");
final BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
String action = intent.getAction();
if (BluetoothDevice.ACTION_ACL_CONNECTED.equalsIgnoreCase(action))
{
Log.d(TAG, "Connected to " + device.getName());
}
if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equalsIgnoreCase(action))
{
Log.d(TAG, "Disconnected from " + device.getName());
}
}}
But when connecting and disconnecting from bluetooth, nothing happens. What am I doing wrong?