当前,我正在尝试管理通知栏上的按钮,但是无法使用addAction
调用函数,因为我必须调用未决的Intent,而不是函数。检查下面的代码:
MainActivity.java
Notification.MediaStyle style = new Notification.MediaStyle();
Bitmap notificationLargeIconBitmap = BitmapFactory.decodeResource(this.getResources(), R.drawable.ic_play_circle_filled_black_24dp);
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.setAction(intent.ACTION_MEDIA_BUTTON);
PendingIntent pendingIntent = PendingIntent.getService(getApplicationContext(), 1, intent, 0);
Notification.Builder builder = new Notification.Builder(this)
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setSmallIcon(R.drawable.ic_play_circle_outline_black_40dp)
.setLargeIcon(notificationLargeIconBitmap)
.setContentTitle(title)
.setContentText(author)
.setDeleteIntent(pendingIntent)
.setColor(this.getResources().getColor(R.color.colorPrimary))
.setPriority(Notification.PRIORITY_MAX)
.addAction(R.drawable.ic_skip_previous_black_24dp, "Prev", pendingIntent)
.addAction(R.drawable.ic_pause_black_24dp, "PlayOrPause", pendingIntent)
.addAction(R.drawable.ic_skip_next_black_24dp, "Next", pendingIntent)
.setStyle(style);
notificationManager.notify(0, builder.build());
请注意.addAction(R.drawable.ic_pause_black_24dp, "PlayOrPause", pendingIntent)
,而不是pendingIntent,是否可以正确地调用playorpause()
?如果尝试,我会得到error: cannot find symbol variable playorpause
你能帮我吗?谢谢。