简体   繁体   English

Android设备通过配对的蓝牙设备唤醒

[英]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. 我在Jelly Bean上有一个Android设备,当希望在蓝牙范围内检测到已配对的设备时,我希望它唤醒。 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 . 注册一个BroadcastReceiver来监听BluetoothDevice.ACTION_BOND_STATE_CHANGED

Inside a BroadcastReciever: 在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 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM