为了捕获蓝牙状态更改( STATE_OFF , STATE_TURNING_ON , STATE_ON , STATE_TURNING_OFF ),请在您的活动中执行此操作:
首先,为您的AndroidManifest文件添加蓝牙权限:
在您的活动或服务中创建BroadcastReceiver:
private final BroadcastReceiver mBroadcastReceiver1 = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) { final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR); switch(state) { case BluetoothAdapter.STATE_OFF: .. break; case BluetoothAdapter.STATE_TURNING_OFF: .. break; case BluetoothAdapter.STATE_ON: .. break; case BluetoothAdapter.STATE_TURNING_ON: .. break; } } } };
创建一个IntentFilter并在onCreate()方法中将BroadcastReceiver注册到Activity / Service:
@Override protected void onCreate(Bundle savedInstanceState) { su
如果觉得《android 蓝牙连接广播 Android广播接收器蓝牙事件捕捉》对你有帮助,请点赞、收藏,并留下你的观点哦!