• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Listening for Bluetooth Status

I'm writing a code that listens for the Bluetooth device to become disconnected, then does something when the device is disconnected. How would I go about doing this? I'm not exactly sure what I want to put after it yet, figured I'd get this sorted out first. Hopefully I wasn't completely wrong with this code, as I'm new to developing. This is what I have so far:

Code:
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

           if (BluetoothAdapter.ACTION_ACL_DISCONNECTED.equals(action))
           { // This will be the followup action, once I figure out what I want it to be.
 
Welcome to AF!

You're on the right track for sure.

You'll want to be sure to register the intent filter in java at some point to start listening, and be sure to declare in your manifest that your activity wants to listen for that intent.
 
Back
Top Bottom