BroadcastReceiver详解(二)

来源:互联网 发布:淘宝商家支付宝反现金 编辑:程序博客网 时间:2024/06/06 21:06

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);

隐式

  1.         <receiver android:name=".MyReceiver">  
  2.             <intent-filter>  
  3.                 <action android:name="android.intent.action.MY_BROADCAST1"/> 
  4. <action android:name="android.intent.action.MY_BROADCAST2"/> 
  5. <action android:name="android.intent.action.MY_BROADCAST3"/> 

  6.                 <category android:name="android.intent.category.DEFAULT" />  
  7.             </intent-filter>  
  8.         </receiver>

0 0
原创粉丝点击