我想使用新的Android L MediaStyle模板创建媒体播放通知.现在,我成功完成了以前,播放,暂停,下一步等操作(通过使用addAction(),但我无法找到添加"关闭"按钮的方法,如Android Notifications Documentation屏幕截图中所示:

有没有一种巧妙的方法来实现这一目标?我希望"关闭"按钮终止当前正在播放的播放,清除播放通知,并按照附带的屏幕截图进行定位.
android android-notifications android-mediaplayer android-5.0-lollipop
我已经使用setOnClick挂起意图编辑了代码,这段代码适用于ImageView和通知文本,我想要分开,但我仍然需要一些帮助.
我想暂停或从我的服务类中播放媒体播放器,那么如何从Notification pending intent访问stop或play方法?
有人说广播接收器会帮助你,但我不知道它是如何起作用的.我已经设法从通知中的暂停按钮打开Web浏览器,但我不知道如何访问服务方法.如果您有一些示例代码,请分享.
@SuppressWarnings("deprecation")
void showNotification() {
int pendingRequestCode = 0;
int pendingFlag = 0;
final Resources res = getResources();
final NotificationManager notificationManager = (NotificationManager) getSystemService(
NOTIFICATION_SERVICE);
Intent intent = new Intent(this,MainActivity.class);
PendingIntent pi= PendingIntent.getActivity(this, 0, intent, 0);
Notification.Builder builder = new Notification.Builder(this)
.setSmallIcon(R.drawable.ic_action_search)
.setAutoCancel(true)
.setTicker("this is notification")
.setContentIntent(pi);
// Sets a custom content view for the notification, including an image button.
RemoteViews layout = new RemoteViews(getPackageName(), R.layout.notification);
layout.setTextViewText(R.id.notification_title, getString(R.string.app_name));
Intent clickIntent = new Intent(Intent.ACTION_VIEW, Uri_myBlog);
PendingIntent pendingIntent …Run Code Online (Sandbox Code Playgroud) android ×2