Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/181.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_Broadcastreceiver - Fatal编程技术网

Android 广播接收机未呼叫

Android 广播接收机未呼叫,android,broadcastreceiver,Android,Broadcastreceiver,我找到了很多关于这个话题的线索,但是我无法解决我的问题。代码如下: 清单文件: <service android:name="com.xxx.player.MediaPlayerService.MediaPlayerService" android:enabled="true" > <intent-filter> <action android:name="and

我找到了很多关于这个话题的线索,但是我无法解决我的问题。代码如下:

清单文件:

<service
            android:name="com.xxx.player.MediaPlayerService.MediaPlayerService"
            android:enabled="true" >
            <intent-filter>
                <action android:name="android.media.AUDIO_BECOMING_NOISY" />
            </intent-filter>

            <receiver android:name="com.xxx.player.MediaPlayerService.MediaPlayerService$ServiceBroadcastReceiver"
                      android:enabled="true"
                      android:exported="false">
                <intent-filter>
                    <action android:name="@string/ACTION_PREPARE_AND_PLAY_NEW_FILE"/>
                    <action android:name="@string/ACTION_PREPARE_NEW_FILE"/>
                    <action android:name="@string/ACTION_START"/>
                    <action android:name="@string/ACTION_STOP"/>
                    <action android:name="@string/ACTION_PAUSE"/>
                    <action android:name="@string/ACTION_SEEK_TO"/>
                    <action android:name="@string/ACTION_RELEASE"/>
                </intent-filter>
            </receiver>
        </service>
我提交意向书的方式:

private void prepareAndPlayNewFile(String mediaData) {
        Intent myIntent = new Intent();
        myIntent.setAction(context.getString(R.string.ACTION_PREPARE_AND_PLAY_NEW_FILE));
        myIntent.putExtra("mediaData", mediaData);
        context.sendBroadcast(myIntent);
    }

您应该将服务绑定到您的活动,而不是使用广播接收器进行消息传递,而不是以这种方式播放媒体

此外,对于您的意图操作,您不应该使用@string/VAR1(我不确定意图过滤器是否适用于这种字符串定义),它始终应该是常量字符串,例如:

android.intent.action.BLAH

我将寻找绑定:)通过
startService()
向服务发送命令比绑定选项更容易。如果你真的想使用消息总线,不要使用常规广播,因为它们是公共的。使用
LocalBroadcastManager
或第三方消息总线(例如,Square的Otto、greenrobot的EventBus)。您建议使用startService()或binding更好吗?最干净、最聪明的方法是什么?它应该与bind配合使用:)
android.intent.action.BLAH