builder.setShowWhen(false);
@Test @Config(minSdk = JELLY_BEAN_MR1) public void build_setShowWhenOnNotification() { Notification notification = builder.setShowWhen(false).build(); assertThat(shadowOf(notification).isWhenShown()).isFalse(); }
@Test @Config(minSdk = JELLY_BEAN_MR1) public void build_whenShowWhenNotSet_setsShowWhenOnNotificationToTrue() { Notification notification = builder.setWhen(100).setShowWhen(true).build(); assertThat(shadowOf(notification).isWhenShown()).isTrue(); }
R.string.remote_verification_notification_failure : R.string.remote_verification_notification_success)) .setShowWhen(true) .setSmallIcon(R.drawable.baseline_security_white_24) .build());
.setContentTitle(context.getString(R.string.sample_submission_notification_title)) .setContentText(context.getString(R.string.sample_submission_notification_content)) .setShowWhen(true) .setSmallIcon(R.drawable.baseline_cloud_upload_white_24) .build());
b = new Notification.Builder(context) .setWhen(n.when) .setShowWhen(showWhen) .setSmallIcon(n.icon, n.iconLevel) .setContent(n.contentView)
b = new Notification.Builder(context) .setWhen(n.when) .setShowWhen(showWhen) .setSmallIcon(n.icon, n.iconLevel) .setContent(n.contentView)
b = new Notification.Builder(context) .setWhen(n.when) .setShowWhen(showWhen) .setSmallIcon(n.icon, n.iconLevel) .setContent(n.contentView)
.setOngoing(false) .setOnlyAlertOnce(true) .setShowWhen(false) .setDeleteIntent(PendingIntent.getService(getBaseContext(), 0, closeIntent, PendingIntent.FLAG_UPDATE_CURRENT));
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); }
.setContentText(contentText) .setWhen(data.updatedDate) .setShowWhen(true);
builder.setShowWhen(false);
private void createNotification() { Log.i(TAG, "Create running notification"); // Create open and pause action intents Intent openIntent = new Intent(this, MainActivity.class); Intent pauseIntent = new Intent(this, ActionReceiver.class); pauseIntent.setAction(Constants.ACTION_UPDATE_STATUS); pauseIntent.putExtra(Constants.Extra.ACTION, Constants.Action.PAUSE); pauseIntent.putExtra(Constants.Extra.BRIGHTNESS, mBrightness); Notification.Action pauseAction = new Notification.Action( R.drawable.ic_wb_incandescent_black_24dp, getString(R.string.notification_action_turn_off), PendingIntent.getBroadcast(getBaseContext(), 0, pauseIntent, Intent.FILL_IN_DATA) ); // Create notification Notification.Builder builder = new Notification.Builder(getApplicationContext()) .setContentTitle(getString(R.string.notification_running_title)) .setContentText(getString(R.string.notification_running_msg)) .setSmallIcon(R.drawable.ic_brightness_2_white_36dp) .addAction(pauseAction) .setContentIntent(PendingIntent.getActivity(getApplicationContext(), 0, openIntent, PendingIntent.FLAG_UPDATE_CURRENT)) .setAutoCancel(false) .setOngoing(true) .setOnlyAlertOnce(true) .setShowWhen(false); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { builder.setChannelId(Constants.NOTIFICATION_CHANNEL_ID_RS); } mNotification = builder.build(); }
public static void registerJob(Context context, long intervalMinutes) { JobScheduler jss = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE); jss.cancel(JOB_ID); long interval = intervalMinutes * MINUTES; long jitter = (long)(INTERVAL_JITTER_FRAC * interval); interval += (long)(Math.random() * (2 * jitter)) - jitter; final JobInfo jobInfo = new JobInfo.Builder(JOB_ID, new ComponentName(context, NekoService.class)) .setMinimumLatency(interval) .setOverrideDeadline(interval + 1000) .build(); Log.v(TAG, "A cat will visit in " + interval + "ms: " + String.valueOf(jobInfo)); jss.schedule(jobInfo); if (NekoLand.DEBUG_NOTIFICATIONS) { NotificationManager noman = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); noman.notify(500, new Notification.Builder(context) .setSmallIcon(R.drawable.stat_icon) .setContentTitle(String.format("Job scheduled in %d min", (interval / MINUTES))) .setContentText(String.valueOf(jobInfo)) .setPriority(Notification.PRIORITY_MIN) .setCategory(Notification.CATEGORY_SERVICE) .setShowWhen(true) .build()); } }
/** * Show a notification while this service is running. */ private void showNotification() { // In this sample, we'll use the same text for the ticker and the expanded notification CharSequence text = getText(R.string.notification_service_not_active); // The PendingIntent to launch our activity if the user selects this notification PendingIntent contentIntent = PendingIntent.getBroadcast(this, 0, new Intent(TOGGLE_ACTIVE_BROADCAST), 0); curNotificationBuilder = new Notification.Builder(this); curNotificationBuilder.setSmallIcon(R.mipmap.ic_screen_rotation_black_48dp) // the status icon .setWhen(System.currentTimeMillis()) // the time stamp .setContentTitle(text) // the label of the entry .setContentText(getText(R.string.touch_to_enable)) // the contents of the entry .setContentIntent(contentIntent) // The intent to send when the entry is clicked .setPriority(Notification.PRIORITY_MIN) .setShowWhen(false) .setOngoing(true); // Send the notification. mNM.notify(NOTIFICATION, curNotificationBuilder.build()); }
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(); }
public void setForegroundEnabled(boolean enabled) { if (enabled) { final Notification notification = new Notification.Builder(this) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle(getText(R.string.app_name)) .setTicker(getText(R.string.foreground_started)) .setContentText(getText(R.string.foreground_started)) .setContentIntent(PendingIntent.getActivity(this, 0, new Intent(this, DevicesActivity.class), 0)) .setShowWhen(false).build(); startForeground(FOREGROUND_ID, notification); } else { stopForeground(true); } }
@Test @Config(minSdk = JELLY_BEAN_MR1) public void build_setsUsesChronometerOnNotification_false() throws Exception { Notification notification = builder.setUsesChronometer(false).setWhen(10).setShowWhen(true).build(); assertThat(shadowOf(notification).usesChronometer()).isFalse(); }
@Test @Config(minSdk = JELLY_BEAN_MR1) public void build_setsUsesChronometerOnNotification_true() throws Exception { Notification notification = builder.setUsesChronometer(true).setWhen(10).setShowWhen(true).build(); assertThat(shadowOf(notification).usesChronometer()).isTrue(); }