Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/210.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 安卓:如何制作单个接收器并在意图之间切换?_Android_Android Intent_Switch Statement_Broadcastreceiver - Fatal编程技术网

Android 安卓:如何制作单个接收器并在意图之间切换?

Android 安卓:如何制作单个接收器并在意图之间切换?,android,android-intent,switch-statement,broadcastreceiver,Android,Android Intent,Switch Statement,Broadcastreceiver,我有两个接收器 <receiver android:name=".BootReceiver" android:enabled="true" > <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </r

我有两个接收器

    <receiver
        android:name=".BootReceiver"
        android:enabled="true" >
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </receiver>
    <receiver
        android:name=".DateReceiver"
        android:enabled="true" >
        <intent-filter>
            <action android:name="android.intent.action.DATE_CHANGED" />
        </intent-filter>
    </receiver>
我想制作一个带有所有
意向过滤器的单一接收器,并在收到意向时进行切换。


    <receiver
        android:name=".DataAndBootReceiver"
        android:enabled="true" >
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.DATE_CHANGED" />
        </intent-filter>
    </receiver>



    public class DataAndBootReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction()
                    .equals("android.intent.action.DATE_CHANGED")) {
                Log.i("Receiver", "Data");
            } else {
                Log.i("Receiver", "Boot");
            }
        }
    }
公共类DataAndBootReceiver扩展了BroadcastReceiver{ @凌驾 公共void onReceive(上下文、意图){ if(intent.getAction() .equals(“android.intent.action.DATE_CHANGED”)){ 日志i(“接收器”、“数据”); }否则{ Log.i(“接收器”、“引导”); } } }

公共类DataAndBootReceiver扩展了BroadcastReceiver{
@凌驾
公共void onReceive(上下文、意图){
if(intent.getAction()
.equals(“android.intent.action.DATE_CHANGED”)){
日志i(“接收器”、“数据”);
}否则{
Log.i(“接收器”、“引导”);
}
}
}

公共类DataAndBootReceiver扩展了BroadcastReceiver{
@凌驾
公共void onReceive(上下文、意图){
if(intent.getAction()
.equals(“android.intent.action.DATE_CHANGED”)){
日志i(“接收器”、“数据”);
}否则{
Log.i(“接收器”、“引导”);
}
}
}

公共类DataAndBootReceiver扩展了BroadcastReceiver{
@凌驾
公共void onReceive(上下文、意图){
if(intent.getAction()
.equals(“android.intent.action.DATE_CHANGED”)){
日志i(“接收器”、“数据”);
}否则{
Log.i(“接收器”、“引导”);
}
}
}

像这样将其添加到清单中

 <receiver android:name=".EventHandler" >
            <intent-filter>
                <action android:name="android.bluetooth.headset.action.VENDOR_SPECIFIC_HEADSET_EVENT" />
                <action android:name="android.bluetooth.headset.profile.action.AUDIO_STATE_CHANGED" />
                <action android:name="android.bluetooth.headset.profile.action.CONNECTION_STATE_CHANGED" />
                <action android:name="android.bluetooth.adapter.action.STATE_CHANGED" />
                <action android:name="android.net.wifi.STATE_CHANGE" />
                <action android:name="android.intent.action.HEADSET_PLUG"/>
                <action android:name="android.hardware.action.NEW_PICTURE" />
                <action android:name="android.hardware.action.NEW_VIDEO" />
                <action android:name="android.intent.action.SCREEN_OFF" />
                <action android:name="android.intent.action.SCREEN_ON" />
                <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
            </intent-filter>
        </receiver>

像这样将其添加到清单中

 <receiver android:name=".EventHandler" >
            <intent-filter>
                <action android:name="android.bluetooth.headset.action.VENDOR_SPECIFIC_HEADSET_EVENT" />
                <action android:name="android.bluetooth.headset.profile.action.AUDIO_STATE_CHANGED" />
                <action android:name="android.bluetooth.headset.profile.action.CONNECTION_STATE_CHANGED" />
                <action android:name="android.bluetooth.adapter.action.STATE_CHANGED" />
                <action android:name="android.net.wifi.STATE_CHANGE" />
                <action android:name="android.intent.action.HEADSET_PLUG"/>
                <action android:name="android.hardware.action.NEW_PICTURE" />
                <action android:name="android.hardware.action.NEW_VIDEO" />
                <action android:name="android.intent.action.SCREEN_OFF" />
                <action android:name="android.intent.action.SCREEN_ON" />
                <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
            </intent-filter>
        </receiver>

像这样将其添加到清单中

 <receiver android:name=".EventHandler" >
            <intent-filter>
                <action android:name="android.bluetooth.headset.action.VENDOR_SPECIFIC_HEADSET_EVENT" />
                <action android:name="android.bluetooth.headset.profile.action.AUDIO_STATE_CHANGED" />
                <action android:name="android.bluetooth.headset.profile.action.CONNECTION_STATE_CHANGED" />
                <action android:name="android.bluetooth.adapter.action.STATE_CHANGED" />
                <action android:name="android.net.wifi.STATE_CHANGE" />
                <action android:name="android.intent.action.HEADSET_PLUG"/>
                <action android:name="android.hardware.action.NEW_PICTURE" />
                <action android:name="android.hardware.action.NEW_VIDEO" />
                <action android:name="android.intent.action.SCREEN_OFF" />
                <action android:name="android.intent.action.SCREEN_ON" />
                <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
            </intent-filter>
        </receiver>

像这样将其添加到清单中

 <receiver android:name=".EventHandler" >
            <intent-filter>
                <action android:name="android.bluetooth.headset.action.VENDOR_SPECIFIC_HEADSET_EVENT" />
                <action android:name="android.bluetooth.headset.profile.action.AUDIO_STATE_CHANGED" />
                <action android:name="android.bluetooth.headset.profile.action.CONNECTION_STATE_CHANGED" />
                <action android:name="android.bluetooth.adapter.action.STATE_CHANGED" />
                <action android:name="android.net.wifi.STATE_CHANGE" />
                <action android:name="android.intent.action.HEADSET_PLUG"/>
                <action android:name="android.hardware.action.NEW_PICTURE" />
                <action android:name="android.hardware.action.NEW_VIDEO" />
                <action android:name="android.intent.action.SCREEN_OFF" />
                <action android:name="android.intent.action.SCREEN_ON" />
                <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
            </intent-filter>
        </receiver>

我接受这个答案是因为它不使用硬编码字符串但引用我接受这个答案是因为它不使用硬编码字符串但引用我接受这个答案是因为它不使用硬编码字符串但引用我接受这个答案是因为它不使用硬编码字符串而使用引用