androidx.core.app.NotificationCompat.Action Java Examples

The following examples show how to use androidx.core.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: MediaNotificationManager.java    From YouTube-In-Background with MIT License 6 votes vote down vote up
private void addPlayPauseAction(NotificationCompat.Builder builder)
{
    LogHelper.d(TAG, "updatePlayPauseAction");
    String label;
    int icon;
    PendingIntent intent;
    if (playbackState.getState() == STATE_PLAYING) {
        label = exoAudioService.getString(R.string.action_pause);
        icon = R.drawable.ic_pause_white_24dp;
        intent = pauseIntent;
    } else {
        label = exoAudioService.getString(R.string.action_play);
        icon = R.drawable.ic_play_arrow_white_24dp;
        intent = playIntent;
    }
    builder.addAction(new NotificationCompat.Action(icon, label, intent));
}
 
Example #2
Source File: SingleRecipientNotificationBuilder.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public void addActions(@NonNull PendingIntent markReadIntent,
                       @NonNull PendingIntent quickReplyIntent,
                       @NonNull PendingIntent wearableReplyIntent,
                       @NonNull ReplyMethod replyMethod)
{
  Action markAsReadAction = new Action(R.drawable.check,
                                       context.getString(R.string.MessageNotifier_mark_read),
                                       markReadIntent);

  String actionName = context.getString(R.string.MessageNotifier_reply);
  String label      = context.getString(replyMethodLongDescription(replyMethod));

  Action replyAction = new Action(R.drawable.ic_reply_white_36dp,
                                  actionName,
                                  quickReplyIntent);

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
    replyAction = new Action.Builder(R.drawable.ic_reply_white_36dp,
                                     actionName,
                                     wearableReplyIntent)
        .addRemoteInput(new RemoteInput.Builder(DefaultMessageNotifier.EXTRA_REMOTE_REPLY)
                            .setLabel(label).build())
        .build();
  }

  Action wearableReplyAction = new Action.Builder(R.drawable.ic_reply,
                                                  actionName,
                                                  wearableReplyIntent)
      .addRemoteInput(new RemoteInput.Builder(DefaultMessageNotifier.EXTRA_REMOTE_REPLY)
                          .setLabel(label).build())
      .build();

  addAction(markAsReadAction);
  addAction(replyAction);

  extend(new NotificationCompat.WearableExtender().addAction(markAsReadAction)
                                                  .addAction(wearableReplyAction));
}
 
Example #3
Source File: NotificationBuilder.java    From YouTube-In-Background with MIT License 5 votes vote down vote up
public NotificationBuilder(Context context)
{
    this.context = context;

    notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    skipToPreviousAction = new Action(
            R.drawable.exo_controls_previous,
            context.getString(R.string.notification_skip_to_previous),
            MediaButtonReceiver.buildMediaButtonPendingIntent(context, ACTION_SKIP_TO_PREVIOUS)
    );
    playAction = new Action(
            R.drawable.exo_controls_play,
            context.getString(R.string.notification_play),
            MediaButtonReceiver.buildMediaButtonPendingIntent(context, ACTION_PLAY)
    );
    pauseAction = new Action(
            R.drawable.exo_controls_pause,
            context.getString(R.string.notification_pause),
            MediaButtonReceiver.buildMediaButtonPendingIntent(context, ACTION_PAUSE)
    );
    skipToNextAction = new Action(
            R.drawable.exo_controls_next,
            context.getString(R.string.notification_skip_to_next),
            MediaButtonReceiver.buildMediaButtonPendingIntent(context, ACTION_SKIP_TO_NEXT)
    );

    stopPendingIntent = MediaButtonReceiver.buildMediaButtonPendingIntent(context, ACTION_STOP);
}
 
Example #4
Source File: WearableNotificationWithVoice.java    From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Action buildWearableAction() {
    String replyLabel = mContext.getString(replyLabelResourceId);
    RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY).setLabel(replyLabel).build();
    // Create an intent for the reply action
    if (pendingIntent == null) {
        Intent replyIntent = new Intent(mContext, notificationHandler);
        pendingIntent = PendingIntent.getActivity(mContext, (int) (System.currentTimeMillis() & 0xfffffff), replyIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
    }
    // Create the reply action and add the remote input
    NotificationCompat.Action action = new NotificationCompat.Action.Builder(actionIconResId,
            mContext.getString(actionTitleId), pendingIntent).addRemoteInput(remoteInput).build();
    return action;
}
 
Example #5
Source File: MediaNotificationManager.java    From YouTube-In-Background with MIT License 4 votes vote down vote up
public MediaNotificationManager(BackgroundExoAudioService service) throws RemoteException
    {
        exoAudioService = service;
        context = exoAudioService.getApplicationContext();

        updateSessionToken();

//        mNotificationColor = ResourceHelper.getThemeColor(exoAudioService, R.attr.colorPrimary, Color.DKGRAY);

        notificationManager = (NotificationManager) service.getSystemService(Context.NOTIFICATION_SERVICE);

        String pkg = context.getPackageName();
        pauseIntent = PendingIntent.getBroadcast(
                context,
                REQUEST_CODE,
                new Intent(CUSTOM_ACTION_PAUSE).setPackage(pkg),
                FLAG_CANCEL_CURRENT
        );
        playIntent = PendingIntent.getBroadcast(
                context,
                REQUEST_CODE,
                new Intent(CUSTOM_ACTION_PLAY).setPackage(pkg),
                FLAG_CANCEL_CURRENT
        );
        previousIntent = PendingIntent.getBroadcast(
                context,
                REQUEST_CODE,
                new Intent(CUSTOM_ACTION_PREV).setPackage(pkg),
                FLAG_CANCEL_CURRENT
        );
        nextIntent = PendingIntent.getBroadcast(
                context,
                REQUEST_CODE,
                new Intent(CUSTOM_ACTION_NEXT).setPackage(pkg),
                FLAG_CANCEL_CURRENT
        );
        stopCastIntent = PendingIntent.getBroadcast(
                context,
                REQUEST_CODE,
                new Intent(CUSTOM_ACTION_STOP).setPackage(pkg),
                FLAG_CANCEL_CURRENT
        );


        skipToPreviousAction = new Action(
                R.drawable.exo_controls_previous,
                context.getString(R.string.notification_skip_to_previous),
                previousIntent
        );
        playAction = new Action(
                R.drawable.exo_controls_play,
                context.getString(R.string.notification_play),
                playIntent
        );
        pauseAction = new Action(
                R.drawable.exo_controls_pause,
                context.getString(R.string.notification_pause),
                pauseIntent
        );
        skipToNextAction = new Action(
                R.drawable.exo_controls_next,
                context.getString(R.string.notification_skip_to_next),
                nextIntent
        );

        stopPendingIntent = PendingIntent.getBroadcast(
                context,
                REQUEST_CODE,
                new Intent(CUSTOM_ACTION_STOP).setPackage(pkg),
                FLAG_CANCEL_CURRENT
        );

        Intent clickIntent = new Intent(exoAudioService, MainActivity.class);
        clickIntent.setAction(Intent.ACTION_MAIN);
        clickIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        clickPendingIntent = PendingIntent.getActivity(exoAudioService, 0, clickIntent, 0);

        // Cancel all notifications to handle the case where the Service was killed and
        // restarted by the system.
        if (notificationManager != null) notificationManager.cancelAll();
    }