Search code examples
androidbluetoothandroid-4.2-jelly-beanwakeup

Android device wake up via a paired bluetooth device


I have an Android device on Jelly Bean, and i want it to wake up when an already paired device is detected within the bluetooth range. I guess it's a service broadcast receiver but i don't know how it should work.


Solution

  • Register a BroadcastReceiver to listen for BluetoothDevice.ACTION_BOND_STATE_CHANGED.

    Inside a BroadcastReciever:

    public void onReceive(Context context, Intent intent)
    {
      if (BluetoothDevice.ACTION_BOND_STATE_CHANGED.equals(intent.getAction()))
      {
    
         int bondState = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, -1);
    
           if (bondState == BluetoothDevice.BOND_BONDED)
            {
                  // wake up 
            }           
    
      }
    }