【发布时间】:2015-04-01 12:11:43
【问题描述】:
我有播放音频文件的音乐服务。我从我的活动开始这项服务。当我从通知中单击播放按钮时,我发送带有播放/暂停按钮的通知,我发送广播接收器并且它正在工作。在 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>
【问题讨论】:
标签: android service broadcastreceiver