当蓝牙连接到另一台设备时,我想做一个BroadcastReceiver
通知我。
BroadcastReceiver bluetooth = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction() == android.bluetooth.BluetoothDevice.ACTION_ACL_CONNECTED) {
Toast.makeText(MainActivity.this, "done!", Toast.LENGTH_LONG)
.show();
}
}
};
和
IntentFilter ff = new IntentFilter();
ff.addAction(android.bluetooth.BluetoothDevice.ACTION_ACL_CONNECTED);
registerReceiver(bluetooth, ff);
和 AndroidManifest.xml
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
但是当设备连接时,什么也没有发生,为什么?