BroadcastReceiver的intentfilte可以隐式控制也可以显示控制
显式
receiver = new BlueToothDeviceReceiver(dialogHandler);
IntentFilter intent = new IntentFilter();
intent.addAction(BluetoothDevice.ACTION_FOUND);
intent.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
intent.addAction(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED);
intent.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
intent.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED);
intent.addAction(BluetoothDevice.ACTION_ACL_CONNECTED);
intent.addAction(BluetoothDevice.ACTION_NAME_CHANGED);
intent.setPriority(-1000);
getApplicationContext().registerReceiver(receiver, intent);
隐式
- <receiver android:name=“.MyReceiver”>
- <intent-filter>
- <action android:name=“android.intent.action.MY_BROADCAST1”/>
- <action android:name=“android.intent.action.MY_BROADCAST2”/>
- <action android:name=“android.intent.action.MY_BROADCAST3”/>
- <category android:name=“android.intent.category.DEFAULT” />
- </intent-filter>
- </receiver>