builder.setColor(0xFF000000);
public void raiseBattle(View view) { Notification n=new Notification.Builder(MainActivity.this, CHANNEL_BATTLE) .setContentTitle(getString(R.string.notif_battle_title)) .setContentText(getString(R.string.notif_battle_text)) .setSmallIcon(android.R.drawable.stat_sys_warning) .setBadgeIconType(Notification.BADGE_ICON_SMALL) .setColor(Color.RED) .setColorized(true) .build(); mgr.notify(NOTIF_ID_BATTLE, n); }
builder.setColor(ChatSDK.config().pushNotificationColor);
.setColor(getResources().getColor(R.color.primary));
builder.setContentIntent(pendingIntent); if (Build.VERSION.SDK_INT >= 24) builder.setColor(Color.RED); Notification notification = builder.build(); notificationManager.notify(0 , notification);
public Notification.Builder buildNotification(Context context) { final Bundle extras = new Bundle(); extras.putString("android.substName", context.getString(R.string.app_name)); final Intent intent = new Intent(Intent.ACTION_MAIN) .setClass(context, NekoLand.class) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { return new Notification.Builder(context) .setSmallIcon(Icon.createWithResource(context, R.drawable.stat_icon)) .setLargeIcon(createLargeIcon(context)) .setColor(getBodyColor()) .setPriority(Notification.PRIORITY_DEFAULT) .setContentTitle(NekoService.notificationText) .setShowWhen(true) .setCategory(Notification.CATEGORY_STATUS) .setContentText(getName()) .setContentIntent(PendingIntent.getActivity(context, 0, intent, 0)) .setAutoCancel(true) .setVibrate(PURR) .addExtras(extras); } return new Notification.Builder(context) .setSmallIcon(R.drawable.stat_icon) .setPriority(Notification.PRIORITY_DEFAULT) .setContentTitle(OldService.notificationText) .setContentText(getName()) .setContentIntent(PendingIntent.getActivity(context, 0, intent, 0)) .setAutoCancel(true) .setVibrate(PURR); }
.setContentTitle(getString(R.string.update_notification_downloading)) .setContentText(String.format(getString(R.string.update_notification_downloading_details), updateData.getNumber())) .setColor(getResources().getColor(R.color.colorAccent)) .setProgress(0, 0, true); .setContentTitle(getString(R.string.update_notification_download_fail)) .setContentText(String.format(getString(R.string.update_notification_download_fail_details), updateData.getNumber())) .setColor(getResources().getColor(R.color.colorAccent));
.setContentTitle(context.getString(R.string.update_notification_title)) .setContentText(content) .setColor(context.getResources().getColor(R.color.colorAccent)); notificationBuider.setPriority(Notification.PRIORITY_HIGH).setVibrate(new long[0]); notificationBuider.addAction(downloadAction);
/** * Sets the color in the notification builder if the property is set in the intent. * * @param context The current context. * @param pushIntent The push intent. * @param builder The builder to modify. */ private static void setColor(Context context, Intent pushIntent, Notification.Builder builder) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { return; } /* Check custom color from intent. */ String colorString = PushIntentUtils.getColor(pushIntent); if (colorString != null) { try { builder.setColor(Color.parseColor(colorString)); return; } catch (IllegalArgumentException e) { AppCenterLog.error(LOG_TAG, "Invalid color string received in push payload.", e); } } /* Check default color. */ int colorResourceId = getResourceIdFromMetadata(context, DEFAULT_COLOR_METADATA_NAME); if (colorResourceId != 0) { AppCenterLog.debug(LOG_TAG, "Using color specified in meta-data for notification."); builder.setColor(getColor(context, colorResourceId)); } }
public Notification.Builder buildNotification(Context context) { final Bundle extras = new Bundle(); extras.putString(NotificationHooks.EXTRA_SUBSTITUTE_APP_NAME, context.getString(R.string.notification_name)); final Intent intent = new Intent(Intent.ACTION_MAIN) .setClass(context, NekoLand.class) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); return new Notification.Builder(context) .setSmallIcon(R.drawable.stat_icon) .setLargeIcon(createNotificationLargeIcon(context)) .setColor(getBodyColor()) .setPriority(Notification.PRIORITY_LOW) .setContentTitle(context.getString(R.string.notification_title)) .setShowWhen(true) .setCategory(Notification.CATEGORY_STATUS) .setContentText(getName()) .setContentIntent(PendingIntent.getActivity(context, 0, intent, 0)) .setAutoCancel(true) .setVibrate(PURR) .addExtras(extras); }
private Notification buildNotification() { final Resources res = getResources(); final String contentTitle = res.getString(R.string.notification_title); final String contentText = res.getString(mVisibleWindow ? R.string.notification_message_visible : R.string.notification_message_hidden); final String intentAction = mVisibleWindow ? ACTION_HIDE : ACTION_SHOW; Intent actionIntent = new Intent(this, TermuxFloatService.class).setAction(intentAction); Notification.Builder builder = new Notification.Builder(this).setContentTitle(contentTitle).setContentText(contentText) .setPriority(Notification.PRIORITY_MIN).setSmallIcon(R.mipmap.ic_service_notification) .setColor(0xFF000000) .setContentIntent(PendingIntent.getService(this, 0, actionIntent, 0)) .setOngoing(true) .setShowWhen(false); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { setupNotificationChannel(); builder.setChannelId(NOTIFICATION_CHANNEL_ID); } //final int messageId = mVisibleWindow ? R.string.toggle_hide : R.string.toggle_show; //builder.addAction(android.R.drawable.ic_menu_preferences, res.getString(messageId), PendingIntent.getService(this, 0, actionIntent, 0)); return builder.build(); }
private Notification.Builder getBuilder(String requestId, Resource.UploadStatus status) { Notification.Builder builder = new Notification.Builder(this) .setSmallIcon(R.drawable.ic_launcher) .setAutoCancel(true) .setContentIntent(PendingIntent.getActivity(this, 1234, new Intent(this, MainActivity.class) .setAction(actionFromStatus(status)) , 0)) .setLargeIcon(getBitmap(requestId)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { builder.setChannelId(MainApplication.NOTIFICATION_CHANNEL_ID); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { builder.setColor(getResources().getColor(R.color.colorPrimary)); } return builder; }
@Test public void handleNotificationWithDefaultColorLollipop() throws Exception { setVersionSdkInt(Build.VERSION_CODES.LOLLIPOP_MR1); int resourceId = 42; int color = 0x424242; Bundle bundle = mock(Bundle.class); when(bundle.getInt(DEFAULT_COLOR_METADATA_NAME)).thenReturn(resourceId); mApplicationInfoMock.metaData = bundle; Resources resourcesMock = mock(Resources.class); when(mContextMock.getResources()).thenReturn(resourcesMock); when(resourcesMock.getColor(eq(resourceId))).thenReturn(color); PushNotifier.handleNotification(mContextMock, new Intent()); verify(mNotificationBuilderMock).setColor(eq(color)); verify(mNotificationManagerMock).notify(mDummyGoogleMessageId.hashCode(), mNotificationMock); }
public Notification21_x(Context context, int icon, CharSequence tickerText, long when) { super(context, icon, tickerText, when); mBuilder.setColor(Color.argb(255, 2, 119, 189)); }
@SuppressLint("InlinedApi") @Test public void handleNotificationWithColorKitKat() throws Exception { setVersionSdkInt(Build.VERSION_CODES.KITKAT); String colorString = "#331144"; when(PushIntentUtils.getColor(any(Intent.class))).thenReturn(colorString); PushNotifier.handleNotification(mContextMock, new Intent()); verify(mNotificationBuilderMock, never()).setColor(anyInt()); verify(mNotificationManagerMock).notify(mDummyGoogleMessageId.hashCode(), mNotificationMock); }
String title = MyApp.getAppContext().getResources().getString(R.string.notification_content_title); Notification.Builder builder = new Notification.Builder(context) .setContentTitle(title) .setContentText(contentText); if (Build.VERSION.SDK_INT >= ApiHelper.VERSION_CODES.LOLLIPOP) { builder.setColor(color); } Notification notification = builder.build();
@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)); } }
@Test public void handleNotificationWithDefaultColor() { int resourceId = 42; int color = 0x424242; Bundle bundle = mock(Bundle.class); when(bundle.getInt(DEFAULT_COLOR_METADATA_NAME)).thenReturn(resourceId); mApplicationInfoMock.metaData = bundle; when(mContextMock.getColor(eq(resourceId))).thenReturn(color); PushNotifier.handleNotification(mContextMock, new Intent()); verify(mNotificationBuilderMock).setColor(eq(color)); verify(mNotificationManagerMock).notify(mDummyGoogleMessageId.hashCode(), mNotificationMock); }
@Test public void handleNotificationWithInvalidColor() { String colorString = "invalid"; when(PushIntentUtils.getColor(any(Intent.class))).thenReturn(colorString); when(Color.parseColor(anyString())).thenThrow(new IllegalArgumentException("Unknown color")); PushNotifier.handleNotification(mContextMock, new Intent()); verify(mNotificationBuilderMock, never()).setColor(anyInt()); verify(mNotificationManagerMock).notify(mDummyGoogleMessageId.hashCode(), mNotificationMock); }
@SuppressLint("InlinedApi") @Test public void handleNotificationWithColor() { String colorString = "#331144"; when(PushIntentUtils.getColor(any(Intent.class))).thenReturn(colorString); PushNotifier.handleNotification(mContextMock, new Intent()); verifyStatic(); Color.parseColor(eq(colorString)); verify(mNotificationBuilderMock).setColor(anyInt()); verify(mNotificationManagerMock).notify(mDummyGoogleMessageId.hashCode(), mNotificationMock); }