use of androidx.core.app.TaskStackBuilder in project Tusky by Vavassor.
the class NotificationHelper method newNotification.
private static NotificationCompat.Builder newNotification(Context context, Notification body, AccountEntity account, boolean summary) {
Intent summaryResultIntent = new Intent(context, MainActivity.class);
summaryResultIntent.putExtra(ACCOUNT_ID, account.getId());
TaskStackBuilder summaryStackBuilder = TaskStackBuilder.create(context);
summaryStackBuilder.addParentStack(MainActivity.class);
summaryStackBuilder.addNextIntent(summaryResultIntent);
PendingIntent summaryResultPendingIntent = summaryStackBuilder.getPendingIntent((int) (notificationId + account.getId() * 10000), PendingIntent.FLAG_UPDATE_CURRENT);
// we have to switch account here
Intent eventResultIntent = new Intent(context, MainActivity.class);
eventResultIntent.putExtra(ACCOUNT_ID, account.getId());
TaskStackBuilder eventStackBuilder = TaskStackBuilder.create(context);
eventStackBuilder.addParentStack(MainActivity.class);
eventStackBuilder.addNextIntent(eventResultIntent);
PendingIntent eventResultPendingIntent = eventStackBuilder.getPendingIntent((int) account.getId(), PendingIntent.FLAG_UPDATE_CURRENT);
Intent deleteIntent = new Intent(context, NotificationClearBroadcastReceiver.class);
deleteIntent.putExtra(ACCOUNT_ID, account.getId());
PendingIntent deletePendingIntent = PendingIntent.getBroadcast(context, summary ? (int) account.getId() : notificationId, deleteIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, getChannelId(account, body)).setSmallIcon(R.drawable.ic_notify).setContentIntent(summary ? summaryResultPendingIntent : eventResultPendingIntent).setDeleteIntent(deletePendingIntent).setColor(BuildConfig.FLAVOR == "green" ? Color.parseColor("#19A341") : ContextCompat.getColor(context, R.color.tusky_blue)).setGroup(account.getAccountId()).setAutoCancel(true).setShortcutId(Long.toString(account.getId())).setDefaults(// So it doesn't ring twice, notify only in Target callback
0);
setupPreferences(account, builder);
return builder;
}
use of androidx.core.app.TaskStackBuilder in project Signal-Android by WhisperSystems.
the class ShortcutLauncherActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String rawId = getIntent().getStringExtra(KEY_RECIPIENT);
if (rawId == null) {
Toast.makeText(this, R.string.ShortcutLauncherActivity_invalid_shortcut, Toast.LENGTH_SHORT).show();
// TODO [greyson] Navigation
startActivity(MainActivity.clearTop(this));
finish();
return;
}
Recipient recipient = Recipient.live(RecipientId.from(rawId)).get();
// TODO [greyson] Navigation
TaskStackBuilder backStack = TaskStackBuilder.create(this).addNextIntent(MainActivity.clearTop(this));
CommunicationActions.startConversation(this, recipient, null, backStack);
finish();
}
use of androidx.core.app.TaskStackBuilder in project android_packages_apps_Settings by omnirom.
the class SimActivationNotifier method sendNetworkConfigNotification.
/**
* Sends a push notification for the SIM activation. It should be called after DSDS reboot.
*/
public void sendNetworkConfigNotification() {
SubscriptionInfo activeRemovableSub = getActiveRemovableSub();
if (activeRemovableSub == null) {
Log.e(TAG, "No removable subscriptions found. Do not show notification.");
return;
}
CharSequence displayName = SubscriptionUtil.getUniqueSubscriptionDisplayName(activeRemovableSub, mContext);
String carrierName = TextUtils.isEmpty(displayName) ? mContext.getString(R.string.sim_card_label) : displayName.toString();
String title = mContext.getString(R.string.post_dsds_reboot_notification_title_with_carrier, carrierName);
String text = mContext.getString(R.string.post_dsds_reboot_notification_text);
Intent clickIntent = new Intent(mContext, Settings.MobileNetworkListActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext).addNextIntent(clickIntent);
PendingIntent contentIntent = stackBuilder.getPendingIntent(0, /* requestCode */
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
Notification.Builder builder = new Notification.Builder(mContext, SIM_SETUP_CHANNEL_ID).setContentTitle(title).setContentText(text).setContentIntent(contentIntent).setSmallIcon(R.drawable.ic_sim_alert).setAutoCancel(true);
mNotificationManager.notify(SIM_ACTIVATION_NOTIFICATION_ID, builder.build());
}
use of androidx.core.app.TaskStackBuilder in project xabber-android by redsolution.
the class NotificationManager method updateNotifications.
/**
* Update notifications for specified provider.
*
* @param <T>
* @param provider
* @param notify Ticker to be shown. Can be <code>null</code>.
*/
public <T extends NotificationItem> void updateNotifications(NotificationProvider<T> provider, T notify) {
int id = providers.indexOf(provider);
if (id == -1) {
throw new IllegalStateException("registerNotificationProvider() must be called from onLoaded() method.");
}
id += BASE_NOTIFICATION_PROVIDER_ID;
Iterator<? extends NotificationItem> iterator = provider.getNotifications().iterator();
if (!iterator.hasNext()) {
notificationManager.cancel(id);
return;
}
NotificationItem top;
String ticker;
if (notify == null) {
top = iterator.next();
ticker = null;
} else {
top = notify;
ticker = top.getTitle();
}
String channelID = provider.getChannelID();
if (channelID.equals(NotificationChannelUtils.DEFAULT_ATTENTION_CHANNEL_ID))
channelID = NotificationChannelUtils.getChannelID(NotificationChannelUtils.ChannelType.attention);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(application, channelID);
notificationBuilder.setSmallIcon(provider.getIcon());
notificationBuilder.setTicker(ticker);
if (!provider.canClearNotifications()) {
notificationBuilder.setOngoing(true);
}
notificationBuilder.setContentTitle(top.getTitle());
notificationBuilder.setContentText(top.getText());
TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(application);
taskStackBuilder.addNextIntentWithParentStack(top.getIntent());
notificationBuilder.setContentIntent(taskStackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT));
if (ticker != null) {
setNotificationDefaults(notificationBuilder, SettingsManager.eventsLightning(), provider.getSound(), provider.getStreamType());
}
notificationBuilder.setDeleteIntent(clearNotifications);
notificationBuilder.setColor(ColorManager.getInstance().getAccountPainter().getDefaultMainColor());
notify(id, notificationBuilder.build());
}
use of androidx.core.app.TaskStackBuilder in project zype-android by zype.
the class VideoCastNotificationService method build.
/*
* Build the RemoteViews for the notification. We also need to add the appropriate "back stack"
* so when user goes into the CastPlayerActivity, she can have a meaningful "back" experience.
*/
private void build(MediaInfo info, Bitmap bitmap, boolean isPlaying) throws CastException, TransientNetworkDisconnectionException, NoConnectionException {
// Playback PendingIntent
Intent playbackIntent = new Intent(ACTION_TOGGLE_PLAYBACK);
playbackIntent.setPackage(getPackageName());
PendingIntent playbackPendingIntent = PendingIntent.getBroadcast(this, 0, playbackIntent, 0);
// Disconnect PendingIntent
Intent stopIntent = new Intent(ACTION_STOP);
stopIntent.setPackage(getPackageName());
PendingIntent stopPendingIntent = PendingIntent.getBroadcast(this, 0, stopIntent, 0);
// Main Content PendingIntent
Bundle mediaWrapper = Utils.mediaInfoToBundle(mCastManager.getRemoteMediaInformation());
Intent contentIntent = new Intent(this, mTargetActivity);
contentIntent.putExtra("media", mediaWrapper);
// Media metadata
MediaMetadata metadata = info.getMetadata();
String castingTo = getResources().getString(R.string.ccl_casting_to_device, mCastManager.getDeviceName());
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(mTargetActivity);
stackBuilder.addNextIntent(contentIntent);
if (stackBuilder.getIntentCount() > 1) {
stackBuilder.editIntentAt(1).putExtra("media", mediaWrapper);
}
PendingIntent contentPendingIntent = stackBuilder.getPendingIntent(NOTIFICATION_ID, PendingIntent.FLAG_UPDATE_CURRENT);
int pauseOrStopResourceId = 0;
if (info.getStreamType() == MediaInfo.STREAM_TYPE_LIVE) {
pauseOrStopResourceId = R.drawable.ic_notification_stop_48dp;
} else {
pauseOrStopResourceId = R.drawable.ic_notification_pause_48dp;
}
int pauseOrPlayTextResourceId = isPlaying ? R.string.ccl_pause : R.string.ccl_play;
NotificationCompat.Builder builder = (NotificationCompat.Builder) new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_stat_action_notification).setContentTitle(metadata.getString(MediaMetadata.KEY_TITLE)).setContentText(castingTo).setContentIntent(contentPendingIntent).setLargeIcon(bitmap).addAction(isPlaying ? pauseOrStopResourceId : R.drawable.ic_notification_play_48dp, getString(pauseOrPlayTextResourceId), playbackPendingIntent).addAction(R.drawable.ic_notification_disconnect_24dp, getString(R.string.ccl_disconnect), stopPendingIntent).setStyle(new androidx.media.app.NotificationCompat.MediaStyle().setShowActionsInCompactView(0, 1).setMediaSession(mCastManager.getMediaSessionCompatToken())).setOngoing(true).setShowWhen(false).setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
mNotification = builder.build();
}
Aggregations