BroadcastReceiver详解(二)

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>
    原文作者:nannannai02
    原文地址: https://blog.csdn.net/nannannai02/article/details/52814043
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞