public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) { if (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1) == BluetoothAdapter.STATE_OFF) { Log.d(TAG, "Bluetooth switched off"); if (mBLEComms != null) { mBLEComms.mBluetoothAdapterStatus = false; mBLEComms.setupComplete = false; } } else if (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1) == BluetoothAdapter.STATE_ON) { Log.d(TAG, "Bluetooth switched on, initialising"); if (mBLEComms != null) { mBLEComms.mBluetoothAdapterStatus = true; mBLEComms.setupBluetooth(); } } } }