- class Receive extends BroadcastReceiver {
- @Override
- public void onReceive(Context context, Intent intent) {
- String action = intent.getAction();
- switch (action) {
- case "play":
- if (mediaPlayer.isPlaying()) {
- mediaPlayer.pause();
- play.setImageDrawable( getResources().getDrawable( R.drawable.play ) );
- remoteViews.setImageViewResource( R.id.nPlay, R.drawable.play );
- notification.bigContentView=remoteViews;
- manager.notify( 1, notification ); //notify 可以直接更新通知 Notification
- } else {
- mediaPlayer.start();
- play.setImageDrawable( getResources().getDrawable( R.drawable.pause ) );
- remoteViews.setImageViewResource( R.id.nPlay, R.drawable.pause );
- notification.bigContentView=remoteViews;
- manager.notify( 1, notification ); //notify 可以直接更新通知 Notification
- }
- break;
- case "lastSong":
- break;
- case "nextSong":
- break;
- }
- }
- }
3, 在 onCreate() 方法里启用广播接收器, 在 onDestroy() 方法里关闭广播接收器
来源: http://www.bubuko.com/infodetail-3171152.html