我创建了一个用于播放流式音频文件的媒体播放器服务,我添加了一个带有暂停操作的通知。我想知道如何在我的服务中获取此操作的操作侦听器。
MediaPlayerService.java
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, new Intent(this, MainActivity.class), 0);
notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
noti = new Notification.Builder(getApplicationContext())
.setOngoing(true)
.setContentTitle("Lecture")
.setTicker("Lecture d'un message en cours")
.setContentText("Message audio en cours")
.setContentIntent(pendingIntent)
.setSmallIcon(R.drawable.ic_launcher)
.addAction(android.R.drawable.ic_media_pause, "Pause", pendingIntent);
notificationManager.notify(0, noti.build());
return START_STICKY;
}