currently I'm trying manage my button at notification bar, but I'm unable to call functions using addAction
, because I must call a pendingIntent, not a function. Check my code below:
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());
Please, note .addAction(R.drawable.ic_pause_black_24dp, "PlayOrPause", pendingIntent)
, instead pendingIntent, is possible call playorpause()
without errors? If I try it, I'll get error: cannot find symbol variable playorpause
Can you help me? Thank you.