@Test @Config(minSdk = M) public void withBigPictureStyle() { Bitmap bigPicture = BitmapFactory.decodeResource( ApplicationProvider.getApplicationContext().getResources(), R.drawable.an_image); Icon bigLargeIcon = Icon.createWithBitmap(bigPicture); Notification notification = builder.setStyle(new Notification.BigPictureStyle(builder) .bigPicture(bigPicture) .bigLargeIcon(bigLargeIcon)) .build(); assertThat(shadowOf(notification).getBigPicture()).isEqualTo(bigPicture); } }
@Test public void withBigTextStyle() { Notification notification = builder.setStyle(new Notification.BigTextStyle(builder) .bigText("BigText") .setBigContentTitle("Title") .setSummaryText("Summary")) .build(); assertThat(shadowOf(notification).getBigText()).isEqualTo("BigText"); assertThat(shadowOf(notification).getBigContentTitle()).isEqualTo("Title"); assertThat(shadowOf(notification).getBigContentText()).isEqualTo("Summary"); assertThat(shadowOf(notification).getBigPicture()).isNull(); }
final String someLongText = "fkdljfdldkfj;ldaksjfkladj;flja;lkjdfljadslfjaddfdsfafjdfad" + "fdl;akjf;lkdf;lkaj;flkjda;lkfjadljflk;adsjfladjflk;dfjlkdjflakdfjdaffjdlfjdjjj" + "adjflkjadlkfjad;lkfjad;sljf;ladkjajlkfjad;lksfjl;akdjf;lkdsajf;lkdjfkadj;flkad" + "jf;lkadjfkldas;lkfja;dljf;lkdasjf;lkadjs;lfjas;ldkfj;lkadsjfl;kadljfl;kasdjf;l" + "jdlskfjklda;fjadslkfj;sdalkfj;ladjf;lajdl;fkajld;kfjlajfl;adjfl;kajdl;fjadl;kfj;"; final Notification.Builder builder = new Notification.Builder(this); builder.setStyle(new Notification.BigTextStyle(builder) .bigText(someLongText) .setBigContentTitle("Big title") .setSummaryText("Big summary")) .setContentTitle("Title") .setContentText("Summary") .setSmallIcon(android.R.drawable.sym_def_app_icon); final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(0, builder.build());
builder.setContentTitle(Math.round(weather.getMain().getTemp()) + temperatureScale + " at " + weather.getName()); builder.setContentText(data); builder.setStyle(new Notification.BigTextStyle().bigText(data)); builder.setSmallIcon(R.drawable.ic_notification_icon); builder.setContentIntent(pendingIntent);
private void processNotify(Bitmap bigPicture, CommanderItem item, String gpioName) { if (bigPicture == null) { bigPicture = BitmapFactory.decodeResource( getResources(), R.drawable.notify_big_picture); } String nm = item.isStatus() ? item.getHighDesc() : item.getLowDesc(); nm = item.getDesc() + ":" + nm; Notification.Builder builder = new Notification.Builder(ListenService.this); PendingIntent pendingIntent = PendingIntent.getActivity(ListenService.this, 0, new Intent(), 0); builder.setSmallIcon(android.R.drawable.ic_popup_reminder) .setTicker(ListenService.this.getString(R.string.app_name)) .setContentTitle(ListenService.this.getString(R.string.app_name)) .setContentText(nm) .setDefaults(Notification.DEFAULT_SOUND) .setContentIntent(pendingIntent) .setAutoCancel(true); Notification.BigPictureStyle bigPictureStyle = new Notification.BigPictureStyle(); bigPictureStyle.bigPicture(bigPicture) .setSummaryText(nm); builder.setStyle(bigPictureStyle); NotificationManager manager =(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = builder.build(); manager.notify(gpioName, 0, notification); }
notificationBuider.setStyle(style);
public static Notification createStatusbarNotification( Context ctxt, PrefsBean prefsBean, KeyFingerprintProvider keyFingerprintProvider) { LOGGER.debug("createStatusbarNotification()"); Notification.Builder builder = createStubNotification( ctxt, R.string.serverRunning, R.string.stopService, NOTIFICATION_CHANNEL_ID); Notification notification = null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { if (prefsBean.showConnectionInfoInNotification()) { String longText = buildLongText(ctxt, prefsBean, keyFingerprintProvider); builder.setStyle(new Notification.BigTextStyle().bigText(longText)); } notification = builder.build(); } else { notification = builder.getNotification(); } notification.flags |= Notification.FLAG_NO_CLEAR; createStatusbarNotification(ctxt, notification, NOTIFICATION_ID); return notification; }
@Override public Notification build() { // Note: this is not a NotificationCompat builder so be mindful of the // API level of methods you call on the builder. Notification.Builder builder = new Notification.Builder(mContext); builder.setContentTitle(mTitle); builder.setContentText(mBody).setStyle(new Notification.BigTextStyle().bigText(mBody)); builder.setSubText(mOrigin); builder.setTicker(mTickerText); builder.setLargeIcon(mLargeIcon); setSmallIconOnBuilder(builder, mSmallIconId, mSmallIconBitmap); builder.setContentIntent(mContentIntent); builder.setDeleteIntent(mDeleteIntent); for (Action action : mActions) { addActionToBuilder(builder, action); } if (mSettingsAction != null) { addActionToBuilder(builder, mSettingsAction); } builder.setDefaults(mDefaults); builder.setVibrate(mVibratePattern); builder.setWhen(mTimestamp); builder.setOnlyAlertOnce(!mRenotify); return builder.build(); } }
@Override public void writeResult(PrintWriter out) { NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); if (!TextUtils.isEmpty(inputString)) { if (inputString.contains("\n")) { Notification.BigTextStyle style = new Notification.BigTextStyle(); style.bigText(inputString); notification.setStyle(style); } else { notification.setContentText(inputString); } } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_TITLE, NotificationManager.IMPORTANCE_DEFAULT); manager.createNotificationChannel(channel); notification.setChannelId(CHANNEL_ID); } manager.notify(notificationId, 0, notification.build()); } });
private static Notification buildNotification(Service context, String channelId) { // Create Pending Intents. PendingIntent piLaunchMainActivity = getLaunchActivityPI(context); PendingIntent piStopService = getStopServicePI(context); // Action to stop the service. Notification.Action stopAction = new Notification.Action.Builder( STOP_ACTION_ICON, getNotificationStopActionText(context), piStopService) .build(); // Create a notification. return new Notification.Builder(context, channelId) .setContentTitle(getNotificationTitle(context)) .setContentText(getNotificationContent(context)) .setSmallIcon(SMALL_ICON) .setContentIntent(piLaunchMainActivity) .setActions(stopAction) .setStyle(new Notification.BigTextStyle()) .build(); }
Intent intent = new Intent(context,ListDetail.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(ListDetail.class); stackBuilder.addNextIntent(intent); PendingIntent contentIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); NotificationManager mNotifM = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Notification.Builder mBuilder = new Notification.Builder(context); mNotifM.notify(NotificationId.getID(), mBuilder.setStyle(new Notification.BigTextStyle(mBuilder) .bigText(bigText) .setBigContentTitle(title) .setSummaryText(summaryText)) .setContentTitle(title) .setSmallIcon(icon) .setContentText(summaryText) .setAutoCancel(true) .setContentIntent(contentIntent) .setTicker(bigText) .build());
@Override public void onReceive(Context context, Intent intent) { Object[] smsExtra = (Object[]) intent.getExtras().get("pdus"); String body = ""; for (int i = 0; i < smsExtra.length; ++i) { SmsMessage sms = SmsMessage.createFromPdu((byte[]) smsExtra[i]); body += sms.getMessageBody(); } Notification notification = new Notification.Builder(context) .setContentText(body) .setContentTitle("New Message") .setSmallIcon(R.drawable.ic_alert) .setStyle(new Notification.BigTextStyle().bigText(body)) .build(); NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(context); notificationManagerCompat.notify(1, notification); }
final String someLongText = "......"; final Notification.Builder builder = new Notification.Builder(this); builder.setStyle(new Notification.BigTextStyle(builder) .bigText(someLongText) .setBigContentTitle("Big title") .setSummaryText("Big summary")) .setContentTitle("Title") .setContentText("Summary"); final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(0, builder.build());
public Notification16_20(Context context, int icon, CharSequence tickerText, long when) { super(context, icon, tickerText, when); mBuilder.setStyle(new Notification.InboxStyle()); }
@Override public void onCreate() { Notification.Builder builder = new Notification.Builder(this) .setSmallIcon(R.drawable.ic_stat_n) .setContentTitle(getString(R.string.update_warning)) .setContentText(getString(R.string.update_warning_details)) .setStyle(new Notification.BigTextStyle().bigText(getString(R.string.update_warning_details))) .setPriority(Notification.PRIORITY_MAX) .setColor(getResources().getColor(R.color.colorAccent)); startForeground(10, builder.build()); sendBroadcast(new Intent(XposedHook.ACTION_MARK_UNSTABLE).setPackage(XposedHook.PACKAGE_SYSTEMUI)); } }
Notification.Builder notificationBuilder = new Notification.Builder(mService); notificationBuilder .setStyle(new Notification.MediaStyle() .setShowActionsInCompactView(new int[]{playPauseButtonPosition}) // show only play/pause in compact view .setMediaSession(mSessionToken)) .setColor(mNotificationColor) .setSmallIcon(R.drawable.ic_notification) .setVisibility(Notification.VISIBILITY_PUBLIC) .setUsesChronometer(true) .setContentIntent(createContentIntent(description)) // Create an intent that would open the UI when user clicks the notification .setContentTitle(description.getTitle()) .setContentText(description.getSubtitle()) .setLargeIcon(art).build()
@Override public void call(Bitmap bitmap) { if (bitmap != null) { builder.setStyle(new Notification.BigPictureStyle() .bigPicture(bitmap) .setBigContentTitle(msg.title()) .setSummaryText(msg.message())); } manager.notify(msg.hashCode(), builder.build()); } });
@Test public void handlePushBigText() { PushNotifier.handleNotification(mContextMock, new Intent()); verify(mNotificationManagerMock).notify(anyInt(), any(Notification.class)); verifyStatic(); PushIntentUtils.setMessageId(eq(mDummyGoogleMessageId), same(mActionIntentMock)); /* Verify we apply big text style. */ ArgumentCaptor<Notification.BigTextStyle> styleArgumentCaptor = ArgumentCaptor.forClass(Notification.BigTextStyle.class); verify(mNotificationBuilderMock).setStyle(styleArgumentCaptor.capture()); verify(styleArgumentCaptor.getValue()).bigText("message"); }
.setSmallIcon(appIconResId).setWhen(System.currentTimeMillis()) .setContentTitle(message) .setStyle(new Notification.BigTextStyle().bigText(message)) .setAutoCancel(true) .setContentText(message) .setContentText(message) .setAutoCancel(true) .setStyle(new Notification.BigTextStyle().bigText(message)) .setContentIntent(pIntent).getNotification();
.setSmallIcon(appIconResId).setWhen(System.currentTimeMillis()) .setContentTitle(message) .setStyle(new Notification.BigTextStyle().bigText(message)) .setAutoCancel(true) .setContentText(message) .setContentText(message) .setAutoCancel(true) .setStyle(new Notification.BigTextStyle().bigText(message)) .setContentIntent(pIntent).getNotification();