我正在开发一个 android 应用程序,我正在检查两个设备是否通过蓝牙连接
我正在使用以下代码注册广播接收器。
IntentFilter filter1 = new IntentFilter(BluetoothDevice.ACTION_ACL_CONNECTED);
IntentFilter filter2 = new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED);
this.registerReceiver(mReceiver, filter1);
this.registerReceiver(mReceiver, filter2);
BroadcastReceiver 看起来像这样。
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
// When discovery finds a device
if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action))
{
Log.e("bluetooth connected","bluetooth connected");
}
else if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action))
{
Log.e("bluetooth not connected","bluetooth not connected");
}
}
};
这怎么行不通。不确定我哪里出错了。请帮忙!谢谢!