@Inject SyncDelegate(Context context, RestServiceFactory factory, ReadabilityClient readabilityClient) { mContext = context; mSharedPreferences = context.getSharedPreferences( context.getPackageName() + SYNC_PREFERENCES_FILE, Context.MODE_PRIVATE); mHnRestService = factory.create(HackerNewsClient.BASE_API_URL, HackerNewsClient.RestService.class, new BackgroundThreadExecutor()); mReadabilityClient = readabilityClient; mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel(DOWNLOADS_CHANNEL_ID, context.getString(R.string.notification_channel_downloads), NotificationManager.IMPORTANCE_LOW); mNotificationManager.createNotificationChannel(channel); mNotificationBuilder = new NotificationCompat.Builder(context, DOWNLOADS_CHANNEL_ID); } else { //noinspection deprecation mNotificationBuilder = new NotificationCompat.Builder(context); } mNotificationBuilder .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher)) .setSmallIcon(R.drawable.ic_notification) .setGroup(NOTIFICATION_GROUP_KEY) .setOnlyAlertOnce(true) .setCategory(NotificationCompat.CATEGORY_PROGRESS) .setAutoCancel(true); }
private void ensure509Builder() { if (m509dBuilder != null) { return; } m509dBuilder = new NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID) .setSmallIcon(R.drawable.ic_stat_alert) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)) .setContentText(getString(R.string.stat_509_alert_title)) .setContentText(getString(R.string.stat_509_alert_text)) .setAutoCancel(true) .setOngoing(false) .setCategory(NotificationCompat.CATEGORY_ERROR) .setChannelId(CHANNEL_ID); m509Delay = new NotificationDelay(this, mNotifyManager, m509dBuilder, ID_509); }
protected NotificationCompat.Builder createAndInitializeNotificationBuilder(Account account) { return notificationHelper.createNotificationBuilder(account, NotificationChannelManager.ChannelType.MESSAGES) .setSmallIcon(getNewMailNotificationIcon()) .setColor(account.getChipColor()) .setWhen(System.currentTimeMillis()) .setAutoCancel(true) .setCategory(NotificationCompat.CATEGORY_EMAIL); }
public SimpleNotificationBuilder setCategory(String category) { mBuilder.setCategory(category); return this; }
@Override public Builder setCategory(String category) { super.setCategory(category); return this; }
private void listing11_23(NotificationCompat.Builder builder) { // Listing 11-23: Setting a Notification category and sender builder.setCategory(NotificationCompat.CATEGORY_CALL) .addPerson("tel:5558675309"); }
.setTicker(getString(R.string.app_name)) .setSound(null) .setCategory(Notification.CATEGORY_STATUS) .setVisibility(Notification.VISIBILITY_SECRET) .setContentText(notificationText)
.setTicker(ctx.getString(R.string.app_name)) .setSound(null) .setCategory(Notification.CATEGORY_STATUS) .setVisibility(Notification.VISIBILITY_SECRET) .setContentText(notificationText)
.setCategory(Notification.CATEGORY_ERROR) .setVisibility(Notification.VISIBILITY_SECRET) .setContentTitle(ctx.getString(R.string.error_notification_title))
.setTicker(context.getString(R.string.app_name)) .setChannelId(CHANNEL_ID) .setCategory(Notification.CATEGORY_STATUS) .setVisibility(Notification.VISIBILITY_SECRET) .setOnlyAlertOnce(true)
.setCategory(Notification.CATEGORY_SERVICE) .setSound(null) .setSmallIcon(R.drawable.notification_quest)
public void showStopSyncthingWarningNotification() { final String msg = mContext.getString(R.string.appconfig_receiver_background_enabled); NotificationCompat.Builder nb = getNotificationBuilder(mInfoChannel) .setContentText(msg) .setTicker(msg) .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)) .setContentTitle(mContext.getText(mContext.getApplicationInfo().labelRes)) .setSmallIcon(R.drawable.ic_stat_notify) .setAutoCancel(true) .setContentIntent(PendingIntent.getActivity(mContext, 0, new Intent(mContext, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { nb.setCategory(Notification.CATEGORY_ERROR); } mNotificationManager.notify(ID_STOP_BACKGROUND_WARNING, nb.build()); } }
/** * 通知を表示します。 */ private static Notification createNotification(Context context) { final NotificationCompat.Builder builder = new NotificationCompat.Builder(context, context.getString(R.string.default_floatingview_channel_id)); builder.setWhen(System.currentTimeMillis()); builder.setSmallIcon(R.mipmap.ic_launcher); builder.setContentTitle(context.getString(R.string.mail_content_title)); builder.setContentText(context.getString(R.string.content_text)); builder.setOngoing(true); builder.setPriority(NotificationCompat.PRIORITY_MIN); builder.setCategory(NotificationCompat.CATEGORY_SERVICE); // PendingIntent作成 final Intent notifyIntent = new Intent(context, DeleteActionActivity.class); PendingIntent notifyPendingIntent = PendingIntent.getActivity(context, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(notifyPendingIntent); return builder.build(); }
/** * 通知を表示します。 * クリック時のアクションはありません。 */ private static Notification createNotification(Context context) { final NotificationCompat.Builder builder = new NotificationCompat.Builder(context, context.getString(R.string.default_floatingview_channel_id)); builder.setWhen(System.currentTimeMillis()); builder.setSmallIcon(R.mipmap.ic_launcher); builder.setContentTitle(context.getString(R.string.chathead_content_title)); builder.setContentText(context.getString(R.string.content_text)); builder.setOngoing(true); builder.setPriority(NotificationCompat.PRIORITY_MIN); builder.setCategory(NotificationCompat.CATEGORY_SERVICE); return builder.build(); } }
public void showFetchingMailNotification(Account account, Folder folder) { String accountName = account.getDescription(); String folderServerId = folder.getServerId(); String folderName = folder.getName(); String tickerText = resourceProvider.checkingMailTicker(accountName, folderName); String title = resourceProvider.checkingMailTitle(); //TODO: Use format string from resources String text = accountName + resourceProvider.checkingMailSeparator() + folderName; int notificationId = NotificationIds.getFetchingMailNotificationId(account); PendingIntent showMessageListPendingIntent = actionBuilder.createViewFolderPendingIntent( account, folderServerId, notificationId); NotificationCompat.Builder builder = notificationHelper.createNotificationBuilder(account, NotificationChannelManager.ChannelType.MISCELLANEOUS) .setSmallIcon(resourceProvider.getIconCheckingMail()) .setWhen(System.currentTimeMillis()) .setOngoing(true) .setTicker(tickerText) .setContentTitle(title) .setContentText(text) .setContentIntent(showMessageListPendingIntent) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setCategory(NotificationCompat.CATEGORY_SERVICE); if (NOTIFICATION_LED_WHILE_SYNCING) { notificationHelper.configureNotification(builder, null, null, account.getNotificationSetting().getLedColor(), NOTIFICATION_LED_BLINK_FAST, true); } getNotificationManager().notify(notificationId, builder.build()); }
public void showAuthenticationErrorNotification(Account account, boolean incoming) { int notificationId = NotificationIds.getAuthenticationErrorNotificationId(account, incoming); PendingIntent editServerSettingsPendingIntent = createContentIntent(account, incoming); String title = resourceProvider.authenticationErrorTitle(); String text = resourceProvider.authenticationErrorBody(account.getDescription()); NotificationCompat.Builder builder = notificationHelper .createNotificationBuilder(account, NotificationChannelManager.ChannelType.MISCELLANEOUS) .setSmallIcon(resourceProvider.getIconWarning()) .setWhen(System.currentTimeMillis()) .setAutoCancel(true) .setTicker(title) .setContentTitle(title) .setContentText(text) .setContentIntent(editServerSettingsPendingIntent) .setStyle(new BigTextStyle().bigText(text)) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setCategory(NotificationCompat.CATEGORY_ERROR); notificationHelper.configureNotification(builder, null, null, NOTIFICATION_LED_FAILURE_COLOR, NOTIFICATION_LED_BLINK_FAST, true); getNotificationManager().notify(notificationId, builder.build()); }
public void showSendFailedNotification(Account account, Exception exception) { String title = resourceProvider.sendFailedTitle(); String text = ExceptionHelper.getRootCauseMessage(exception); int notificationId = NotificationIds.getSendFailedNotificationId(account); PendingIntent folderListPendingIntent = actionBuilder.createViewFolderListPendingIntent( account, notificationId); NotificationCompat.Builder builder = notificationHelper .createNotificationBuilder(account, NotificationChannelManager.ChannelType.MISCELLANEOUS) .setSmallIcon(resourceProvider.getIconWarning()) .setWhen(System.currentTimeMillis()) .setAutoCancel(true) .setTicker(title) .setContentTitle(title) .setContentText(text) .setContentIntent(folderListPendingIntent) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setCategory(NotificationCompat.CATEGORY_ERROR); notificationHelper.configureNotification(builder, null, null, NOTIFICATION_LED_FAILURE_COLOR, NOTIFICATION_LED_BLINK_FAST, true); getNotificationManager().notify(notificationId, builder.build()); }
@SuppressWarnings("deprecation") private void ensureDownloadingBuilder() { if (mDownloadingBuilder != null) { return; } Intent stopAllIntent = new Intent(this, DownloadService.class); stopAllIntent.setAction(ACTION_STOP_ALL); PendingIntent piStopAll = PendingIntent.getService(this, 0, stopAllIntent, 0); mDownloadingBuilder = new NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID) .setSmallIcon(android.R.drawable.stat_sys_download) .setOngoing(true) .setAutoCancel(false) .setCategory(NotificationCompat.CATEGORY_PROGRESS) .setColor(getResources().getColor(R.color.colorPrimary)) .addAction(R.drawable.ic_pause_x24, getString(R.string.stat_download_action_stop_all), piStopAll) .setShowWhen(false) .setChannelId(CHANNEL_ID); mDownloadingDelay = new NotificationDelay(this, mNotifyManager, mDownloadingBuilder, ID_DOWNLOADING); }
public void showCertificateErrorNotification(Account account, boolean incoming) { int notificationId = NotificationIds.getCertificateErrorNotificationId(account, incoming); PendingIntent editServerSettingsPendingIntent = createContentIntent(account, incoming); String title = resourceProvider.certificateErrorTitle(account.getDescription()); String text = resourceProvider.certificateErrorBody(); NotificationCompat.Builder builder = notificationHelper .createNotificationBuilder(account, NotificationChannelManager.ChannelType.MISCELLANEOUS) .setSmallIcon(resourceProvider.getIconWarning()) .setWhen(System.currentTimeMillis()) .setAutoCancel(true) .setTicker(title) .setContentTitle(title) .setContentText(text) .setContentIntent(editServerSettingsPendingIntent) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setCategory(NotificationCompat.CATEGORY_ERROR); notificationHelper.configureNotification(builder, null, null, NOTIFICATION_LED_FAILURE_COLOR, NOTIFICATION_LED_BLINK_FAST, true); getNotificationManager().notify(notificationId, builder.build()); }
private Builder createPublicNotification(NotificationData notificationData) { Account account = notificationData.getAccount(); int newMessages = notificationData.getNewMessagesCount(); int unreadCount = notificationData.getUnreadMessageCount(); String title = resourceProvider.newMessagesTitle(newMessages); return notificationHelper.createNotificationBuilder(account, NotificationChannelManager.ChannelType.MESSAGES) .setSmallIcon(resourceProvider.getIconNewMail()) .setColor(account.getChipColor()) .setNumber(unreadCount) .setContentTitle(title) .setCategory(NotificationCompat.CATEGORY_EMAIL); }