Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.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 从BroadcastReceiver启动服务从不调用Service.onStartCommand()方法_Android_Service_Broadcastreceiver - Fatal编程技术网

Android 从BroadcastReceiver启动服务从不调用Service.onStartCommand()方法

Android 从BroadcastReceiver启动服务从不调用Service.onStartCommand()方法,android,service,broadcastreceiver,Android,Service,Broadcastreceiver,我有播放音频文件的音乐服务。我从我的活动开始这项服务。当我从“我发送广播接收器的通知”中单击“播放”按钮时,我使用“播放/暂停”按钮发送通知,该按钮正在工作。在onReceive(Context-Context,Intent-Intent)方法中,我调用Context.startService(intentService),问题是MusicService.onStartCommand()从未被调用 我的听筒 public class PlayEpisodeReceiver extends Bro

我有播放音频文件的音乐服务。我从我的活动开始这项服务。当我从“我发送广播接收器的通知”中单击“播放”按钮时,我使用“播放/暂停”按钮发送通知,该按钮正在工作。在onReceive(Context-Context,Intent-Intent)方法中,我调用Context.startService(intentService),问题是MusicService.onStartCommand()从未被调用

我的听筒

public class PlayEpisodeReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        Toast.makeText(context, "Service Started", Toast.LENGTH_SHORT).show();
        if(MusicService.isRunning()) {

            Intent serviceIntent = new Intent(context, MusicService.class);

            serviceIntent.putExtra(AppConstants.ACTION_TYPE, AppConstants.ACTION_PLAY);

            context.startService(intent);
        }
    }

} 
我的舱单:

<service
            android:enabled="true"
            android:name=".backgroundtasks.MusicService">
            <intent-filter>
                <action
                    android:name = "cc.gm.oscarradio.backgroundtasks.MusicService">
                </action>
            </intent-filter>
        </service>
        <receiver
            android:enabled="true"
            android:name=".Receivers.PlayEpisodeReceiver">
            <intent-filter>
                <action android:name = "cc.gm.oscarradio.ACTION_MUSIC"/>
            </intent-filter>
        </receiver>

我觉得您的代码中应该有一点变化,您应该替换以下行:

context.startService(intent);


希望这对您有所帮助。

在您的代码中,我觉得应该有一点变化,您应该替换以下行:

context.startService(intent);


希望这对您有所帮助。

在您的代码中,我觉得应该有一点变化,您应该替换以下行:

context.startService(intent);


希望这对您有所帮助。

在您的代码中,我觉得应该有一点变化,您应该替换以下行:

context.startService(intent);

希望这对你有帮助