Java Code Examples for android.support.v7.app.NotificationCompat#Action

The following examples show how to use android.support.v7.app.NotificationCompat#Action . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NotificationUtil.java    From Prodigal with Apache License 2.0 6 votes vote down vote up
public void showPlayingNotification(PlayerService service, MediaSessionCompat session) {
    NotificationCompat.Builder builder = notificationBuilder(service, session);
    if( builder == null ) {
        return;
    }
    NotificationCompat.Action action;
    if (session.isActive()) {
        action = new NotificationCompat.Action(android.R.drawable.ic_media_pause, "Pause", playIntent);
    } else {
        action = new NotificationCompat.Action(android.R.drawable.ic_media_play, "Play", pauseIntent);
    }
    builder.addAction(new NotificationCompat.Action(android.R.drawable.ic_media_previous, "Previous",
            prevIntent));
    builder.addAction(action);
    builder.addAction(new NotificationCompat.Action(android.R.drawable.ic_media_next, "Next",
            nextIntent));

    builder.setOngoing(true);

    builder.setStyle(new NotificationCompat.MediaStyle().setShowActionsInCompactView(1).setMediaSession(session.getSessionToken()));
    builder.setSmallIcon(R.mipmap.ic_launcher);
    NotificationManagerCompat.from(service).notify(NOTIFICATION_ID, builder.build());
}
 
Example 2
Source File: TrackNotification.java    From Melophile with Apache License 2.0 5 votes vote down vote up
private NotificationCompat.Action pause(Context context) {
  Intent playPauseIntent = new Intent(context, MusicPlaybackService.class);
  playPauseIntent.setAction(ACTION_PAUSE);

  PendingIntent pausePendingIntent = PendingIntent.getService(context,
          PAUSE_PENDING_INTENT_ID,
          playPauseIntent,
          PendingIntent.FLAG_UPDATE_CURRENT);
  return new NotificationCompat.Action(R.drawable.ic_pause_notif, "Pause", pausePendingIntent);
}
 
Example 3
Source File: TrackNotification.java    From Melophile with Apache License 2.0 5 votes vote down vote up
private NotificationCompat.Action next(Context context) {
  Intent nextIntent = new Intent(context, MusicPlaybackService.class);
  nextIntent.setAction(ACTION_NEXT);

  PendingIntent nextPendingIntent = PendingIntent.getService(context,
          PLAY_NEXT_PENDING_INTENT_ID,
          nextIntent,
          PendingIntent.FLAG_UPDATE_CURRENT);
  return new NotificationCompat.Action(R.drawable.ic_skip_next_notif, "Next", nextPendingIntent);
}
 
Example 4
Source File: TrackNotification.java    From Melophile with Apache License 2.0 5 votes vote down vote up
private NotificationCompat.Action prev(Context context) {
  Intent prevIntent = new Intent(context, MusicPlaybackService.class);
  prevIntent.setAction(ACTION_PREV);

  PendingIntent prevPendingIntent = PendingIntent.getService(context,
          PLAY_PREV_PENDING_INTENT_ID,
          prevIntent,
          PendingIntent.FLAG_UPDATE_CURRENT);
  return new NotificationCompat.Action(R.drawable.ic_skip_prev_notif, "Previous", prevPendingIntent);
}
 
Example 5
Source File: TrackNotification.java    From Melophile with Apache License 2.0 5 votes vote down vote up
private NotificationCompat.Action play(Context context) {
  Intent prevIntent = new Intent(context, MusicPlaybackService.class);
  prevIntent.setAction(ACTION_PLAY);

  PendingIntent prevPendingIntent = PendingIntent.getService(context,
          PLAY_PENDING_INTENT_ID,
          prevIntent,
          PendingIntent.FLAG_UPDATE_CURRENT);
  return new NotificationCompat.Action(R.drawable.ic_play_notif, "Play", prevPendingIntent);
}