private NotificationCompat.Action createCancelAction(int notId) { int cancelIcon = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? R.drawable.ic_close : R.drawable.ic_notification_close; return new NotificationCompat.Action.Builder(cancelIcon, mContext.getString(R.string.action_cancel), PendingIntent.getBroadcast(mContext, notId, ActionReceiver.getCancelIntent(mContext, notId), PendingIntent.FLAG_UPDATE_CURRENT)) .build(); }
NotificationCompat.Action.Builder shareAction = new NotificationCompat.Action.Builder( R.drawable.ic_share_white, device.getContext().getString(R.string.share), sharePendingIntent); builder.addAction(shareAction.build());
private NotificationCompat.Action makeShutdownAction() { Intent shutdownIntent = new Intent(getApplicationContext(), NotificationReceiver.class); shutdownIntent.setAction(NotificationReceiver.NOTIFY_ACTION_SHUTDOWN_APP); PendingIntent shutdownPendingIntent = PendingIntent.getBroadcast( getApplicationContext(), 0, shutdownIntent, PendingIntent.FLAG_UPDATE_CURRENT); return new NotificationCompat.Action.Builder( R.drawable.ic_power_settings_new_white_24dp, getString(R.string.shutdown), shutdownPendingIntent) .build(); }
replyActionPendingIntent) .addRemoteInput(remoteInput) .build();
NotificationCompat.Action prevAction = new NotificationCompat.Action.Builder(R.drawable.ic_skip_previous_48dp, "Previous", prevPendingIntent).build(); playPauseIcon = R.drawable.ic_play_arrow_48dp; NotificationCompat.Action playPauseAction = new NotificationCompat.Action.Builder(playPauseIcon, "PlayPause", playPauseIntent).build(); NotificationCompat.Action nextAction = new NotificationCompat.Action.Builder(R.drawable.ic_skip_next_48dp, "Next", nextPendingIntent).build();
replyActionPendingIntent) .addRemoteInput(remoteInput) .build();
.setLabel(context.getString(R.string.action_reply)) .build()) .build(); notification .setContentTitle(title)
NotificationCompat.Action cancelAction = new NotificationCompat.Action.Builder(R.drawable.ic_close_24dp, getString(R.string.dialog_action_cancel), nextPendingIntent).build();
private void runAsForeground() { if (mBroadcastReceiver == null) { mBroadcastReceiver = new ActionReceiver(); // Create a filter to only handle certain actions IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(ACTION_CANCEL_BULKDOWNLOAD); registerReceiver(mBroadcastReceiver, intentFilter); } mBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID) .setContentTitle(getString(R.string.downloader_notification_title)) .setStyle(new NotificationCompat.BigTextStyle() .bigText(getString(R.string.downloader_notification_remaining_images) + ' ' + String.valueOf(mSumImageDownloads - (mRemainingArtists + mRemainingAlbums)) + '/' + String.valueOf(mSumImageDownloads))) .setProgress(mSumImageDownloads, mSumImageDownloads - (mRemainingArtists + mRemainingAlbums), false) .setSmallIcon(R.drawable.odyssey_notification); openChannel(); mBuilder.setOngoing(true); // Cancel action Intent nextIntent = new Intent(BulkDownloadService.ACTION_CANCEL_BULKDOWNLOAD); PendingIntent nextPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 1, nextIntent, PendingIntent.FLAG_UPDATE_CURRENT); androidx.core.app.NotificationCompat.Action cancelAction = new androidx.core.app.NotificationCompat.Action.Builder(R.drawable.ic_close_24dp, getString(R.string.dialog_action_cancel), nextPendingIntent).build(); mBuilder.addAction(cancelAction); Notification notification = mBuilder.build(); startForeground(NOTIFICATION_ID, notification); mNotificationManager.notify(NOTIFICATION_ID, notification); }
private NotificationCompat.Action makeFuncButtonAction() { Intent funcButtonIntent = new Intent(getApplicationContext(), NotificationReceiver.class); int type = pref.getInt(getString(R.string.pref_key_foreground_notify_func_button), SettingsManager.Default.funcButton(getApplicationContext())); int icon = 0; String text = null; if (type == Integer.parseInt(getString(R.string.pref_function_button_pause_value))) { funcButtonIntent.setAction(NotificationReceiver.NOTIFY_ACTION_PAUSE_RESUME); boolean isPause = isPauseButton.get(); icon = (isPause ? R.drawable.ic_pause_white_24dp : R.drawable.ic_play_arrow_white_24dp); text = (isPause ? getString(R.string.pause_torrent) : getString(R.string.resume_torrent)); } else if (type == Integer.parseInt(getString(R.string.pref_function_button_add_value))) { funcButtonIntent.setAction(NotificationReceiver.NOTIFY_ACTION_ADD_TORRENT); icon = R.drawable.ic_add_white_36dp; text = getString(R.string.add); } PendingIntent funcButtonPendingIntent = PendingIntent.getBroadcast( getApplicationContext(), 0, funcButtonIntent, PendingIntent.FLAG_UPDATE_CURRENT); return new NotificationCompat.Action.Builder(icon, text, funcButtonPendingIntent).build(); }
@TargetApi(Build.VERSION_CODES.N) private static void createInlineReply( Context ctx, NotificationCompat.Builder builder, NotificationEntity entity) { RemoteInput remoteInput = new RemoteInput.Builder(Constants.EXTRA_COMMENT) .setLabel(ctx.getString(R.string.change_details_review_hint)) .setAllowFreeFormInput(true) .build(); NotificationCompat.Action action = new NotificationCompat.Action.Builder( R.drawable.ic_send, ctx.getString(R.string.action_reply), getReplyPendingIntent(ctx, entity)) .addRemoteInput(remoteInput) .setAllowGeneratedReplies(false) .build(); builder.addAction(action); }
final NotificationCompat.Action toAction() { return new NotificationCompat.Action.Builder(icon, title, actionIntent).build(); }