androidx.core.app.NotificationCompat Java Examples
The following examples show how to use
androidx.core.app.NotificationCompat.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NotificationUtils.java From DoraemonKit with Apache License 2.0 | 6 votes |
/** * 文本消息 * * @param notifyId 消息ID * @param title 标题 * @param summary 内容 * @param ticker 出现消息时状态栏的提示文字 * @param pendingIntent 点击后的intent */ public static void setMessageNotification(Context context, int notifyId, int smallIconId, CharSequence title, CharSequence summary, CharSequence ticker, PendingIntent pendingIntent) { NotificationCompat.Builder builder; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { builder = new NotificationCompat.Builder(context, ID_HIGH_CHANNEL); } else { builder = new NotificationCompat.Builder(context); } builder.setSmallIcon(smallIconId) .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.dk_doraemon)) .setContentTitle(title) .setContentText(summary) .setAutoCancel(true) .setProgress(0, 0, false);// Removes the progress bar if (!TextUtils.isEmpty(ticker)) { builder.setTicker(ticker); } if (pendingIntent != null) { builder.setContentIntent(pendingIntent); } else { builder.setContentIntent(PendingIntent.getBroadcast(context, 0, new Intent(), PendingIntent.FLAG_UPDATE_CURRENT)); } NotificationManager manager = createNotificationManager(context); manager.notify(notifyId, builder.build()); }
Example #2
Source File: NotificationActionUtils.java From abnd-track-pomodoro-timer-app with MIT License | 6 votes |
/** * @param currentlyRunningServiceType The next service that shall be run * @return Returns Action Buttons and assigns pendingIntents to Actions */ public static NotificationCompat.Action getIntervalAction(int currentlyRunningServiceType, Context context) { switch (currentlyRunningServiceType) { case TAMETU: return new NotificationCompat.Action( R.drawable.play, context.getString(R.string.start_tametu), getPendingIntent(TAMETU, INTENT_VALUE_START, context)); case SHORT_BREAK: return new NotificationCompat.Action( R.drawable.short_break, context.getString(R.string.start_short_break), getPendingIntent(SHORT_BREAK, INTENT_VALUE_SHORT_BREAK, context)); case LONG_BREAK: return new NotificationCompat.Action( R.drawable.long_break, context.getString(R.string.start_long_break), getPendingIntent(LONG_BREAK, INTENT_VALUE_LONG_BREAK, context)); default: return null; } }
Example #3
Source File: UploaderNotificationHelper.java From TowerCollector with Mozilla Public License 2.0 | 6 votes |
private Notification prepareNotification(String notificationText) { // set style builder.setSmallIcon(R.drawable.ic_notification); builder.setColor(context.getResources().getColor(R.color.ic_notification_background_color)); builder.setWhen(System.currentTimeMillis()); builder.setOnlyAlertOnce(true); // set intent PendingIntent cancelUploaderIntent = createCancelUploaderIntent(); builder.setContentIntent(cancelUploaderIntent); // set message builder.setContentTitle(context.getString(R.string.uploader_notification_title)); builder.setContentText(notificationText); builder.setTicker(notificationText); builder.setStyle(new NotificationCompat.BigTextStyle().bigText(notificationText)); return builder.build(); }
Example #4
Source File: UARTService.java From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Creates the notification * * @param messageResId message resource id. The message must have one String parameter,<br /> * f.e. <code><string name="name">%s is connected</string></code> * @param defaults signals that will be used to notify the user */ @SuppressWarnings("SameParameterValue") protected Notification createNotification(final int messageResId, final int defaults) { final Intent parentIntent = new Intent(this, FeaturesActivity.class); parentIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); final Intent targetIntent = new Intent(this, UARTActivity.class); final Intent disconnect = new Intent(ACTION_DISCONNECT); disconnect.putExtra(EXTRA_SOURCE, SOURCE_NOTIFICATION); final PendingIntent disconnectAction = PendingIntent.getBroadcast(this, DISCONNECT_REQ, disconnect, PendingIntent.FLAG_UPDATE_CURRENT); // both activities above have launchMode="singleTask" in the AndroidManifest.xml file, so if the task is already running, it will be resumed final PendingIntent pendingIntent = PendingIntent.getActivities(this, OPEN_ACTIVITY_REQ, new Intent[]{parentIntent, targetIntent}, PendingIntent.FLAG_UPDATE_CURRENT); final NotificationCompat.Builder builder = new NotificationCompat.Builder(this, ToolboxApplication.CONNECTED_DEVICE_CHANNEL); builder.setContentIntent(pendingIntent); builder.setContentTitle(getString(R.string.app_name)).setContentText(getString(messageResId, getDeviceName())); builder.setSmallIcon(R.drawable.ic_stat_notify_uart); builder.setShowWhen(defaults != 0).setDefaults(defaults).setAutoCancel(true).setOngoing(true); builder.addAction(new NotificationCompat.Action(R.drawable.ic_action_bluetooth, getString(R.string.uart_notification_action_disconnect), disconnectAction)); return builder.build(); }
Example #5
Source File: MediaNotificationManager.java From klingar with Apache License 2.0 | 6 votes |
private void loadImage(final String url, final NotificationCompat.Builder builder) { Glide.with(service) .asBitmap() .load(url) .apply(RequestOptions.overrideOf(iconWidth, iconHeight)) .into(new CustomTarget<Bitmap>() { @Override public void onResourceReady( @NonNull Bitmap resource, Transition<? super Bitmap> transition ) { if (TextUtils.equals(currentTrack.thumb(), url)) { builder.setLargeIcon(resource); notificationManager.notify(NOTIFICATION_ID, builder.build()); } } @Override public void onLoadCleared(@Nullable Drawable placeholder) { } }); }
Example #6
Source File: OCRFloating4.java From loco-answers with GNU General Public License v3.0 | 6 votes |
private void notification() { Intent i = new Intent(this, OCRFloating4.class); i.setAction("stop"); PendingIntent pi = PendingIntent.getService(this, 171, i, 0); PendingIntent pendingIntent = PendingIntent.getActivity(this, 172, new Intent(this, MainActivity.class), 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext(), "stop"); mBuilder.setContentText("Trivia Hack: Committed to speed and performance :)") .setContentTitle("Tap to remove overlay screen") .setPriority(NotificationCompat.PRIORITY_HIGH) .setContentIntent(pi) .setSmallIcon(R.mipmap.ic_launcher_round) .setOngoing(true).setAutoCancel(true) .addAction(android.R.drawable.ic_menu_more, "Open Trivia Hack", pendingIntent); notificationManager.notify(1695, mBuilder.build()); }
Example #7
Source File: SyncMetadataWorker.java From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void triggerNotification(String title, String content, int progress) { NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel mChannel = new NotificationChannel(METADATA_CHANNEL, "MetadataSync", NotificationManager.IMPORTANCE_HIGH); notificationManager.createNotificationChannel(mChannel); } NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getApplicationContext(), METADATA_CHANNEL) .setSmallIcon(R.drawable.ic_sync) .setContentTitle(title) .setContentText(content) .setOngoing(true) .setOnlyAlertOnce(true) .setAutoCancel(false) .setProgress(100, progress, false) .setPriority(NotificationCompat.PRIORITY_DEFAULT); notificationManager.notify(SyncMetadataWorker.SYNC_METADATA_ID, notificationBuilder.build()); }
Example #8
Source File: NotificationBuilderImplBase.java From FCM-for-Mojo with GNU General Public License v3.0 | 6 votes |
@Override void notify(Context context, Chat chat, NotificationBuilder nb) { int id = (int) chat.getUniqueId(); notifyGroupSummary(context, chat, nb); NotificationCompat.Builder builder = createBuilder(context, chat) .setLargeIcon(loadLargeIcon(context, chat)) .setContentTitle(chat.getName()) .setContentText(chat.getLatestMessage().getContent(context)) .setGroup(GROUP_KEY) .setGroupSummary(false) .setShowWhen(true) .setOnlyAlertOnce(chat.getLatestMessage().getSenderUser().getUid() == User.getSelf().getUid()) .setWhen(chat.getLatestMessage().getTimestamp() * 1000) .setStyle(createStyle(context, chat)) .setContentIntent(NotificationBuilder.createContentIntent(context, id, chat)) .setDeleteIntent(NotificationBuilder.createDeleteIntent(context, id, chat)) .setCategory(NotificationCompat.CATEGORY_MESSAGE) .addAction(createReplyAction(context, id, chat)); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(id, builder.build()); }
Example #9
Source File: DownloadTask.java From NetGuard with GNU General Public License v3.0 | 6 votes |
private void showNotification(int progress) { Intent main = new Intent(context, ActivitySettings.class); PendingIntent pi = PendingIntent.getActivity(context, ServiceSinkhole.NOTIFY_DOWNLOAD, main, PendingIntent.FLAG_UPDATE_CURRENT); TypedValue tv = new TypedValue(); context.getTheme().resolveAttribute(R.attr.colorOff, tv, true); NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "notify"); builder.setSmallIcon(R.drawable.ic_file_download_white_24dp) .setContentTitle(context.getString(R.string.app_name)) .setContentText(context.getString(R.string.msg_downloading, url.toString())) .setContentIntent(pi) .setProgress(100, progress, false) .setColor(tv.data) .setOngoing(true) .setAutoCancel(false); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) builder.setCategory(NotificationCompat.CATEGORY_STATUS) .setVisibility(NotificationCompat.VISIBILITY_SECRET); NotificationManagerCompat.from(context).notify(ServiceSinkhole.NOTIFY_DOWNLOAD, builder.build()); }
Example #10
Source File: CheckSourceService.java From a with GNU General Public License v3.0 | 6 votes |
/** * 更新通知 */ private void updateNotification(int state, String msg) { NotificationCompat.Builder builder = new NotificationCompat.Builder(this, MApplication.channelIdReadAloud) .setSmallIcon(R.drawable.ic_network_check) .setOngoing(true) .setContentTitle(getString(R.string.check_book_source)) .setContentText(msg) .setContentIntent(getActivityPendingIntent()); builder.addAction(R.drawable.ic_stop_black_24dp, getString(R.string.cancel), getThisServicePendingIntent()); if (bookSourceBeanList != null) { builder.setProgress(bookSourceBeanList.size(), state, false); } builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC); Notification notification = builder.build(); startForeground(notificationId, notification); }
Example #11
Source File: NotificationUtils.java From DoraemonKit with Apache License 2.0 | 6 votes |
/** * 显示消息中心的消息 * * @param notifyId 消息ID * @param title 标题 * @param summary 内容 * @param ticker 出现消息时状态栏的提示文字 * @param pendingIntent 点击后的intent */ public static void setInfoNotification(Context context, int notifyId, CharSequence title, CharSequence summary, CharSequence ticker, PendingIntent pendingIntent) { NotificationCompat.Builder builder; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { builder = new NotificationCompat.Builder(context, ID_HIGH_CHANNEL); } else { builder = new NotificationCompat.Builder(context); } builder.setSmallIcon(R.mipmap.dk_doraemon) .setContentTitle(title) .setContentText(summary) .setAutoCancel(true) .setProgress(0, 0, false);// Removes the progress bar if (!TextUtils.isEmpty(ticker)) { builder.setTicker(ticker); } if (pendingIntent != null) { builder.setContentIntent(pendingIntent); } else { builder.setContentIntent(PendingIntent.getBroadcast(context, 0, new Intent(), PendingIntent.FLAG_UPDATE_CURRENT)); } NotificationManager manager = createNotificationManager(context); manager.notify(notifyId, builder.build()); }
Example #12
Source File: UpdateService.java From a with GNU General Public License v3.0 | 6 votes |
/** * 更新通知 */ private void updateNotification(int state) { RxBus.get().post(RxBusTag.UPDATE_APK_STATE, state); NotificationCompat.Builder builder = new NotificationCompat.Builder(this, MApplication.channelIdReadAloud) .setSmallIcon(R.drawable.ic_download) .setOngoing(true) .setContentTitle(getString(R.string.download_update)) .setContentText(String.format(getString(R.string.progress_show), state, 100)) .setContentIntent(getActivityPendingIntent()); builder.addAction(R.drawable.ic_stop_black_24dp, getString(R.string.cancel), getThisServicePendingIntent()); builder.setProgress(100, state, false); builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC); Notification notification = builder.build(); int notificationId = 3425; startForeground(notificationId, notification); }
Example #13
Source File: ReactNativeUtil.java From react-native-azurenotificationhub with MIT License | 6 votes |
public static NotificationCompat.Builder initNotificationCompatBuilder(Context context, String notificationChannelID, String title, CharSequence ticker, int visibility, int priority, boolean autoCancel) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, notificationChannelID) .setContentTitle(title) .setTicker(ticker) .setVisibility(visibility) .setPriority(priority) .setAutoCancel(autoCancel); return notificationBuilder; }
Example #14
Source File: OCRFloating.java From loco-answers with GNU General Public License v3.0 | 6 votes |
private void notification() { Intent i = new Intent(this, OCRFloating.class); i.setAction("stop"); PendingIntent pi = PendingIntent.getService(this, 0, i, 0); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext(), "stop"); mBuilder.setContentText("Trivia Hack: Committed to speed and performance :)") .setContentTitle("Tap to remove overlay screen") .setPriority(NotificationCompat.PRIORITY_HIGH) .setContentIntent(pi) .setSmallIcon(R.mipmap.ic_launcher_round) .setOngoing(true).setAutoCancel(true) .addAction(android.R.drawable.ic_menu_more, "Open Trivia Hack", pendingIntent); notificationManager.notify(1545, mBuilder.build()); }
Example #15
Source File: BackgroundAudioService.java From YouTube-In-Background with MIT License | 6 votes |
private void setNotificationPlaybackState(NotificationCompat.Builder builder) { LogHelper.e(TAG, "updateNotificationPlaybackState. mediaPlayer=" + mediaPlayer); if (mediaPlayer == null) { LogHelper.e(TAG, "updateNotificationPlaybackState. cancelling notification!"); stopForeground(true); return; } if (mediaPlayer.isPlaying() && mediaPlayer.getCurrentPosition() >= 0) { LogHelper.e(TAG, "updateNotificationPlaybackState. updating playback position to ", (System.currentTimeMillis() - mediaPlayer.getCurrentPosition()) / 1000, " seconds"); builder.setWhen(System.currentTimeMillis() - mediaPlayer.getCurrentPosition()) .setShowWhen(true) .setUsesChronometer(true); } else { LogHelper.e(TAG, "updateNotificationPlaybackState. hiding playback position"); builder.setWhen(0) .setShowWhen(false) .setUsesChronometer(false); } // Make sure that the notification can be dismissed by the user when we are not playing: builder.setOngoing(mediaPlayer.isPlaying()); }
Example #16
Source File: AN2LinuxService.java From an2linuxclient with GNU General Public License v3.0 | 6 votes |
private void do_foreground() { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder( this, CHANNEL_ID_FOREGROUND_SERVICE ); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){ notificationBuilder.setCategory(Notification.CATEGORY_SERVICE); } else{ notificationBuilder.setPriority(Notification.PRIORITY_MIN); } notificationBuilder.setOngoing(true); notificationBuilder.setSmallIcon(R.drawable.an2linux_icon); notificationBuilder.setTicker(getString(R.string.main_enable_service_notification_channel_name)); notificationBuilder.setContentIntent( PendingIntent.getActivity(this, 0, new Intent(this, MainSettingsActivity.class), PendingIntent.FLAG_UPDATE_CURRENT) ); Notification n = notificationBuilder.build(); startForeground(NOTIFICATION_ID_FOREGROUND_SERVICE, n); }
Example #17
Source File: NotificationObserver.java From Kore with Apache License 2.0 | 6 votes |
private Notification buildNothingPlayingNotification() { int smallIcon = R.drawable.ic_devices_white_24dp; NotificationCompat.Builder builder = new NotificationCompat.Builder(service, NOTIFICATION_CHANNEL); return builder .setSmallIcon(smallIcon) .setShowWhen(false) .setOngoing(true) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setCategory(NotificationCompat.CATEGORY_TRANSPORT) .setContentIntent(remoteStartPendingIntent) .setContentTitle(String.format(service.getString(R.string.connected_to), HostManager.getInstance(service).getHostInfo().getName())) .setContentText(service.getString(R.string.nothing_playing)) .build(); }
Example #18
Source File: DCCNotificationManager.java From revolution-irc with GNU General Public License v3.0 | 6 votes |
private void createSummaryNotification() { if (!isNotificationGroupingEnabled()) return; NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext, NOTIFICATION_CHANNEL) .setContentTitle(mContext.getString(R.string.dcc_summary_notification_title)) .setContentText(mContext.getResources().getQuantityString( R.plurals.dcc_summary_notification_text, mDisplayedNotificationIds.size(), mDisplayedNotificationIds.size())) .setContentIntent(getOpenTransfersIntent()) .setSmallIcon(R.drawable.ic_notification_connected) .setGroup(NOTIFICATION_GROUP_DCC) .setGroupSummary(true) .setOnlyAlertOnce(true); mNotificationManager.notify(DCC_SUMMARY_NOTIFICATION_ID, builder.build()); }
Example #19
Source File: FileDownloaderExecutor.java From Mysplash with GNU Lesser General Public License v3.0 | 6 votes |
@Nullable private NotificationCompat.InboxStyle buildInboxStyle(@Nullable List<String> titleList, float process) { if (titleList != null) { NotificationCompat.InboxStyle inbox = new NotificationCompat.InboxStyle(); inbox.setBigContentTitle(context.getString(R.string.feedback_downloading)); inbox.setSummaryText(((int) process) + "%"); for (int i = 0; i < titleList.size(); i ++) { if (i < 7) { inbox.addLine(titleList.get(i)); } else { inbox.addLine("..."); break; } } return inbox; } else { return null; } }
Example #20
Source File: MobileCellsRegistrationService.java From PhoneProfilesPlus with Apache License 2.0 | 5 votes |
private void showResultNotification() { String text = getString(R.string.mobile_cells_registration_pref_dlg_status_stopped); String newCount = getString(R.string.mobile_cells_registration_pref_dlg_status_new_cells_count); long iValue = DatabaseHandler.getInstance(getApplicationContext()).getNewMobileCellsCount(); newCount = newCount + " " + iValue; text = text + "; " + newCount; if (android.os.Build.VERSION.SDK_INT < 24) { text = text+" ("+getString(R.string.ppp_app_name)+")"; } PPApplication.createMobileCellsRegistrationNotificationChannel(this); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, PPApplication.MOBILE_CELLS_REGISTRATION_NOTIFICATION_CHANNEL) .setColor(ContextCompat.getColor(this, R.color.notificationDecorationColor)) .setSmallIcon(R.drawable.ic_exclamation_notify) // notification icon .setContentTitle(getString(R.string.phone_profiles_pref_applicationEventMobileCellsRegistration_notification)) // title for notification .setContentText(text) // message for notification .setAutoCancel(true); // clear notification after click //mBuilder.setPriority(NotificationCompat.PRIORITY_MAX); //if (android.os.Build.VERSION.SDK_INT >= 21) //{ mBuilder.setCategory(NotificationCompat.CATEGORY_RECOMMENDATION); mBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC); //} Notification notification = mBuilder.build(); NotificationManagerCompat mNotificationManager = NotificationManagerCompat.from(this); try { mNotificationManager.notify( PPApplication.MOBILE_CELLS_REGISTRATION_RESULT_NOTIFICATION_TAG, PPApplication.MOBILE_CELLS_REGISTRATION_RESULT_NOTIFICATION_ID, notification); } catch (Exception e) { //Log.e("MobileCellsRegistrationService.showResultNotification", Log.getStackTraceString(e)); PPApplication.recordException(e); } }
Example #21
Source File: SubscriptionsFeedFragment.java From SkyTube with GNU General Public License v3.0 | 5 votes |
private void showNotification() { // Sets an ID for the notification, so it can be updated. if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { NotificationManager mNotificationManager = (NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE); NotificationChannel mChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, NOTIFICATION_CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH); mChannel.setSound(null,null); // Create a notification and set the notification channel. Notification notification = new Notification.Builder(getContext(), NOTIFICATION_CHANNEL_NAME) .setSmallIcon(R.drawable.ic_notification_icon) .setContentTitle(getString(R.string.fetching_subscription_videos)) .setContentText(String.format(getContext().getString(R.string.fetched_videos_from_channels), numVideosFetched, numChannelsFetched, numChannelsSubscribed)) .setChannelId(NOTIFICATION_CHANNEL_ID) .build(); mNotificationManager.createNotificationChannel(mChannel); // Issue the notification. mNotificationManager.notify(NOTIFICATION_ID , notification); } else { final Intent emptyIntent = new Intent(); PendingIntent pendingIntent = PendingIntent.getActivity(getContext(), 1, emptyIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(getContext(), "") .setSmallIcon(R.drawable.ic_notification_icon) .setContentTitle(getString(R.string.fetching_subscription_videos)) .setContentText(String.format(getContext().getString(R.string.fetched_videos_from_channels), numVideosFetched, numChannelsFetched, numChannelsSubscribed)) .setPriority(NotificationCompat.FLAG_ONGOING_EVENT) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(NOTIFICATION_ID, builder.build()); } }
Example #22
Source File: NotificationUtil.java From android-testdpc with Apache License 2.0 | 5 votes |
public static void showNotification( Context context, @StringRes int titleId, String msg, int notificationId) { NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = getNotificationBuilder(context) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle(context.getString(titleId)) .setContentText(msg) .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)) .build(); notificationManager.notify(notificationId, notification); }
Example #23
Source File: BedtimeNotificationReceiver.java From GotoSleep with GNU General Public License v3.0 | 5 votes |
private void showNotification(Context context, String title, String content) { Intent intent = new Intent(context, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, LAUNCH_APP_REQUEST_CODE, intent, 0); Intent snoozeIntent = new Intent(context, AutoDoNotDisturbReceiver.class); PendingIntent snoozePendingIntent = PendingIntent.getBroadcast(context, DO_NOT_DISTURB_REQUEST_CODE, snoozeIntent, 0); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); // Check if the notification policy access has been granted for the app. NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, BEDTIME_CHANNEL_ID) .setSmallIcon(R.drawable.ic_moon_notification) .setContentTitle(title) .setAutoCancel(true) .setContentText(content) .setContentIntent(pendingIntent) .setPriority(NotificationCompat.PRIORITY_MAX) .setColorized(true) .setColor(context.getResources().getColor(R.color.moonPrimary)); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { if (notificationSoundsEnabled) { //if device does not support notification channels check if notification sound is enabled mBuilder.setDefaults(Notification.DEFAULT_SOUND); mBuilder.setDefaults(Notification.DEFAULT_VIBRATE); mBuilder.setDefaults(Notification.DEFAULT_LIGHTS); } else { mBuilder.setSound(null); } } mBuilder.addAction(R.drawable.ic_do_not_disturb, context.getString(R.string.notifAction), snoozePendingIntent); notificationManager.notify(NOTIFICATION_REQUEST_CODE, mBuilder.build()); }
Example #24
Source File: MockDatabase.java From user-interface-samples with Apache License 2.0 | 5 votes |
private InboxStyleEmailAppData() { // Standard Notification values: // Title/Content for API <16 (4.0 and below) devices. mContentTitle = "5 new emails"; mContentText = "from Jane, Jay, Alex +2 more"; mNumberOfNewEmails = 5; mPriority = NotificationCompat.PRIORITY_DEFAULT; // Style notification values: mBigContentTitle = "5 new emails from Jane, Jay, Alex +2"; mSummaryText = "New emails"; // Add each summary line of the new emails, you can add up to 5. mIndividualEmailSummary = new ArrayList<>(); mIndividualEmailSummary.add("Jane Faab - Launch Party is here..."); mIndividualEmailSummary.add("Jay Walker - There's a turtle on the server!"); mIndividualEmailSummary.add("Alex Chang - Check this out..."); mIndividualEmailSummary.add("Jane Johns - Check in code?"); mIndividualEmailSummary.add("John Smith - Movies later...."); // If the phone is in "Do not disturb mode, the user will still be notified if // the user(s) is starred as a favorite. mParticipants = new ArrayList<>(); mParticipants.add("Jane Faab"); mParticipants.add("Jay Walker"); mParticipants.add("Alex Chang"); mParticipants.add("Jane Johns"); mParticipants.add("John Smith"); // Notification channel values (for devices targeting 26 and above): mChannelId = "channel_email_1"; // The user-visible name of the channel. mChannelName = "Sample Email"; // The user-visible description of the channel. mChannelDescription = "Sample Email Notifications"; mChannelImportance = NotificationManager.IMPORTANCE_DEFAULT; mChannelEnableVibrate = true; mChannelLockscreenVisibility = NotificationCompat.VISIBILITY_PRIVATE; }
Example #25
Source File: CallNotificationBuilder.java From bcm-android with GNU General Public License v3.0 | 5 votes |
public static Notification getCallInProgressNotification(Context context, AccountContext accountContext, int type, @NonNull Recipient recipient) { Intent contentIntent = new Intent(context, ChatRtcCallActivity.class); contentIntent.putExtra(ARouterConstants.PARAM.PARAM_ACCOUNT_CONTEXT, accountContext); // contentIntent.setAction(WebRtcCallService.ACTION_OUTGOING_CALL); PendingIntent pendingIntent = PendingIntent.getActivity(context, REQUEST_SERVICE_TOUCH, contentIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = AmeNotification.INSTANCE.getCustomNotificationBuilder(context, CALL_CHANNEL_DEFAULT, "CALL", context.getString(R.string.common_webrtc_call_channel_description)) .setSmallIcon(R.drawable.ic_call_secure_white_24dp) .setContentIntent(pendingIntent) .setOngoing(true) .setContentTitle(recipient.getName()); ALog.i(TAG, "createCallInProgressNotification, type: " + type); if (type == TYPE_INCOMING_RINGING) { builder.setContentText(context.getString(R.string.common_webrtc_incoming_call)); builder.addAction(getServiceNotificationAction(context, WebRtcCallService.ACTION_DENY_CALL, R.drawable.ic_close_grey600_32dp, R.string.common_webrtc_deny_call)); builder.addAction(getServiceNotificationAction(context, WebRtcCallService.ACTION_ANSWER_CALL, R.drawable.ic_phone_grey600_32dp, R.string.common_webrtc_answer_call)); } else if (type == TYPE_OUTGOING_RINGING) { builder.setContentText(context.getString(R.string.common_webrtc_establishing_call)); builder.addAction(getServiceNotificationAction(context, WebRtcCallService.ACTION_LOCAL_HANGUP, R.drawable.ic_call_end_grey600_32dp, R.string.common_webrtc_cancel_call)); } else { builder.setContentText(context.getString(R.string.common_webrtc_call_in_progress)); builder.addAction(getServiceNotificationAction(context, WebRtcCallService.ACTION_LOCAL_HANGUP, R.drawable.ic_call_end_grey600_32dp, R.string.common_webrtc_end_call)); } return builder.build(); }
Example #26
Source File: CallNotificationBuilder.java From bcm-android with GNU General Public License v3.0 | 5 votes |
public static Notification getCallDefaultNotification(Context context) { NotificationCompat.Builder builder = AmeNotification.INSTANCE.getCustomNotificationBuilder(context, CALL_CHANNEL_DEFAULT, "CALL", context.getString(R.string.common_webrtc_call_default_description)) .setSmallIcon(R.drawable.ic_call_secure_white_24dp) .setAutoCancel(true) .setContentTitle(context.getString(R.string.common_webrtc_call_default_description)); return builder.build(); }
Example #27
Source File: NotificationManager.java From QuickDevFramework with Apache License 2.0 | 5 votes |
/** * set big picture style for notification * @param builder builder * @param title title * @param picture picture, the picture should not higher than 255dp * @param summaryText summary * */ public static NotificationCompat.Builder setBigPicture(NotificationCompat.Builder builder, String title, String summaryText, Bitmap picture) { NotificationCompat.BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle(); bigPictureStyle.setBigContentTitle(title); bigPictureStyle.bigPicture(picture); if (!TextUtils.isEmpty(summaryText)) { bigPictureStyle.setSummaryText(summaryText); } builder.setStyle(bigPictureStyle); return builder; }
Example #28
Source File: ExportBackupService.java From Pix-Art-Messenger with GNU General Public License v3.0 | 5 votes |
private void notifyError() { final String path = FileBackend.getBackupDirectory(); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getBaseContext(), "backup"); mBuilder.setContentTitle(getString(R.string.notification_backup_failed_title)) .setContentText(getString(R.string.notification_backup_failed_subtitle, path)) .setStyle(new NotificationCompat.BigTextStyle().bigText(getString(R.string.notification_backup_failed_subtitle, FileBackend.getBackupDirectory()))) .setAutoCancel(true) .setSmallIcon(R.drawable.ic_warning_white_24dp); notificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
Example #29
Source File: MyFirebaseMessagingService.java From quickstart-android with Apache License 2.0 | 5 votes |
/** * Create and show a simple notification containing the received FCM message. * * @param messageBody FCM message body received. */ private void sendNotification(String messageBody) { Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); String channelId = getString(R.string.default_notification_channel_id); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, channelId) .setSmallIcon(R.drawable.ic_stat_ic_notification) .setContentTitle(getString(R.string.fcm_message)) .setContentText(messageBody) .setAutoCancel(true) .setSound(defaultSoundUri) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // Since android Oreo notification channel is needed. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel(channelId, "Channel human readable title", NotificationManager.IMPORTANCE_DEFAULT); notificationManager.createNotificationChannel(channel); } notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
Example #30
Source File: NotificationUtils.java From live-app-android with MIT License | 5 votes |
public static void sendGpsDisabledError(Context context) { NotificationCompat.Builder builder = createNotification(context, new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS)); builder.setContentTitle(context.getString(R.string.tap_to_turn_location_settings)); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(GPS_DISABLED_ERROR_ID, builder.build()); }