質問

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.

役に立ちましたか?

解決

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 
        }           

  }
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top