您的位置:首页 > 其它

BroadcastReceiver详解(二)

2016-10-14 10:53 169 查看
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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: