BroadcastReceiver详解(二)
2016-10-14 10:53
169 查看
BroadcastReceiver的intentfilte可以隐式控制也可以显示控制
显式
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>
显式
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>
相关文章推荐
- BroadcastReceiver应用详解
- 基础总结篇之五:BroadcastReceiver应用详解 (转载liuhe688)
- Android BroadcastReceiver 详解
- BroadcastReceiver应用详解
- BroadCastReceiver详解
- BroadcastReceiver应用详解(转)
- BroadcastReceiver应用详解
- BroadcastReceiver应用详解
- 基础总结篇之五:BroadcastReceiver应用详解
- BroadcastReceiver应用详解
- BroadcastReceiver应用详解
- BroadcastReceiver应用详解
- (转)BroadcastReceiver应用详解
- BroadcastReceiver应用详解
- BroadcastReceiver应用详解
- BroadcastReceiver应用详解 (转)
- BroadcastReceiver应用详解
- [转]基础总结篇之五:BroadcastReceiver应用详解 .
- BroadcastReceiver应用详解
- 基础总结篇之五:BroadcastReceiver应用详解