Java Code Examples for androidx.core.app.NotificationManagerCompat#from()
The following examples show how to use
androidx.core.app.NotificationManagerCompat#from() .
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: Floating.java From loco-answers with GNU General Public License v3.0 | 6 votes |
private void notification() { Intent i = new Intent(this, Floating.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 most accurate answer") .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 notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(1234, mBuilder.build()); }
Example 2
Source File: Conversation.java From NaviBee with GNU General Public License v3.0 | 6 votes |
public void markAllAsRead() { unreadMsgCount = 0; if (messages.size()>0) { readTimestamp = messages.get(messages.size()-1).getTime_(); // update timestamp on server db.collection("conversations").document(conversationId).update("readTimestamps." + uid, readTimestamp); } Intent intent = new Intent(ConversationManager.BROADCAST_MESSAGE_READ_CHANGE); NaviBeeApplication.getInstance().sendBroadcast(intent); // cancel notification SharedPreferences prefs = NaviBeeApplication.getInstance().getSharedPreferences(MyFirebaseMessagingService.NOTIFICATION_PREFS_NAME, NaviBeeApplication.getInstance().MODE_PRIVATE); Set<String> ids = prefs.getStringSet(conversationId, new HashSet<>()); prefs.edit().remove(conversationId).apply(); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(NaviBeeApplication.getInstance()); for (String idString: ids) { int id = Integer.parseInt(idString); notificationManager.cancel(id); MyFirebaseMessagingService.messages.delete(id); } }
Example 3
Source File: MainSettingsActivity.java From an2linuxclient with GNU General Public License v3.0 | 6 votes |
private void displayNotificationHidingHelp() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){ NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, CHANNEL_ID_INFORMATION); notificationBuilder.setCategory(Notification.CATEGORY_MESSAGE); notificationBuilder.setSmallIcon(R.drawable.an2linux_icon); notificationBuilder.setTicker(getString(R.string.main_enable_service_information_notification_title)); notificationBuilder.setContentIntent( PendingIntent.getActivity(this, 0, new Intent(this, MainSettingsActivity.class), PendingIntent.FLAG_UPDATE_CURRENT) ); notificationBuilder.setAutoCancel(true); notificationBuilder.setContentTitle(getString(R.string.main_enable_service_information_notification_title)); notificationBuilder.setContentText(getString(R.string.main_enable_service_information_notification_text)); notificationBuilder.setStyle(new NotificationCompat.BigTextStyle() .bigText(getString(R.string.main_enable_service_information_notification_text))); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(NOTIFICATION_ID_HIDE_FOREGROUND_NOTIF, notificationBuilder.build()); } }
Example 4
Source File: Event.java From PhoneProfilesPlus with Apache License 2.0 | 6 votes |
private void removeStartEventNotificationAlarm(DataWrapper dataWrapper) { if (_repeatNotificationStart) { /*boolean clearNotification = true; for (int i = eventTimelineList.size()-1; i > 0; i--) { EventTimeline _eventTimeline = eventTimelineList.get(i); Event event = dataWrapper.getEventById(_eventTimeline._fkEvent); if ((event != null) && (event._repeatNotificationStart) && (event._id != this._id)) { // not clear, notification is from another event clearNotification = false; break; } } if (clearNotification) {*/ NotificationManagerCompat notificationManager = NotificationManagerCompat.from(dataWrapper.context); try { notificationManager.cancel( PPApplication.NOTIFY_EVENT_START_NOTIFICATION_TAG+"_"+_id, PPApplication.NOTIFY_EVENT_START_NOTIFICATION_ID + (int) _id); } catch (Exception e) { PPApplication.recordException(e); } StartEventNotificationBroadcastReceiver.removeAlarm(this, dataWrapper.context); //} } }
Example 5
Source File: StandaloneMainActivity.java From android-Notifications with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG, "onCreate()"); setContentView(R.layout.activity_main); // Enables Ambient mode. mAmbientController = AmbientMode.attachAmbientSupport(this); mNotificationManagerCompat = NotificationManagerCompat.from(getApplicationContext()); mMainFrameLayout = findViewById(R.id.mainFrameLayout); mWearableRecyclerView = findViewById(R.id.recycler_view); // Aligns the first and last items on the list vertically centered on the screen. mWearableRecyclerView.setEdgeItemsCenteringEnabled(true); // Customizes scrolling so items farther away form center are smaller. ScalingScrollLayoutCallback scalingScrollLayoutCallback = new ScalingScrollLayoutCallback(); mWearableRecyclerView.setLayoutManager( new WearableLinearLayoutManager(this, scalingScrollLayoutCallback)); // Improves performance because we know changes in content do not change the layout size of // the RecyclerView. mWearableRecyclerView.setHasFixedSize(true); // Specifies an adapter (see also next example). mCustomRecyclerAdapter = new CustomRecyclerAdapter( NOTIFICATION_STYLES, // Controller passes selected data from the Adapter out to this Activity to trigger // updates in the UI/Notifications. new Controller(this)); mWearableRecyclerView.setAdapter(mCustomRecyclerAdapter); }
Example 6
Source File: MyFirebaseMessagingService.java From NaviBee with GNU General Public License v3.0 | 5 votes |
private void sendNotifcation(Notification notification, String convId, int id) { NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(id, notification); saveNotification(id, convId); }
Example 7
Source File: NotificationHelper.java From NekoSMS with GNU General Public License v3.0 | 5 votes |
public static void displayNotification(Context context, Uri messageUri) { if (!areNotificationsEnabled(context)) { BlockedSmsLoader.get().setSeenStatus(context, messageUri, true); return; } SmsMessageData messageData = BlockedSmsLoader.get().query(context, messageUri); Notification notification = buildNotificationSingle(context, messageData); applyNotificationStyle(context, notification); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); notificationManager.notify(uriToNotificationId(messageUri), notification); }
Example 8
Source File: BigTextIntentService.java From user-interface-samples with Apache License 2.0 | 5 votes |
/** * Handles action Dismiss in the provided background thread. */ private void handleActionDismiss() { Log.d(TAG, "handleActionDismiss()"); NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(getApplicationContext()); notificationManagerCompat.cancel(StandaloneMainActivity.NOTIFICATION_ID); }
Example 9
Source File: BigTextIntentService.java From android-Notifications with Apache License 2.0 | 5 votes |
/** * Handles action Dismiss in the provided background thread. */ private void handleActionDismiss() { Log.d(TAG, "handleActionDismiss()"); NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(getApplicationContext()); notificationManagerCompat.cancel(StandaloneMainActivity.NOTIFICATION_ID); }
Example 10
Source File: MrNotification.java From BaseProject with Apache License 2.0 | 5 votes |
public NotificationBuilder aBuilder(Context context, String channelId) { NotificationBuilder builder = new NotificationBuilder(context, channelId); if (notifyManager == null) { notifyManager = NotificationManagerCompat.from(context); // notifyManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); } return builder; }
Example 11
Source File: NotificationService.java From Pix-Art-Messenger with GNU General Public License v3.0 | 5 votes |
public static void cancelIncomingCallNotification(final Context context) { final NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); try { notificationManager.cancel(INCOMING_CALL_NOTIFICATION_ID); } catch (RuntimeException e) { Log.d(Config.LOGTAG, "unable to cancel incoming call notification after crash", e); } }
Example 12
Source File: BigTextIntentService.java From android-Notifications with Apache License 2.0 | 5 votes |
/** * Handles action Dismiss in the provided background thread. */ private void handleActionDismiss() { Log.d(TAG, "handleActionDismiss()"); NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(getApplicationContext()); notificationManagerCompat.cancel(MainActivity.NOTIFICATION_ID); }
Example 13
Source File: ListenerService.java From AndroidAPS with GNU Affero General Public License v3.0 | 5 votes |
private void showBolusProgress(int progresspercent, String progresstatus) { Intent cancelIntent = new Intent(this, ListenerService.class); cancelIntent.setAction(ACTION_CANCELBOLUS); PendingIntent cancelPendingIntent = PendingIntent.getService(this, 0, cancelIntent, 0); long[] vibratePattern; boolean vibreate = PreferenceManager .getDefaultSharedPreferences(this).getBoolean("vibrateOnBolus", true); if(vibreate){ vibratePattern = new long[]{0, 50, 1000}; } else { vibratePattern = new long[]{0, 1, 1000}; } NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_icon) .setContentTitle("Bolus Progress") .setContentText(progresspercent + "% - " + progresstatus) .setContentIntent(cancelPendingIntent) .setPriority(NotificationCompat.PRIORITY_MAX) .setVibrate(vibratePattern) .addAction(R.drawable.ic_cancel, "CANCEL BOLUS", cancelPendingIntent); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); if(confirmThread != null){ confirmThread.invalidate(); } notificationManager.notify(BOLUS_PROGRESS_NOTIF_ID, notificationBuilder.build()); notificationManager.cancel(CONFIRM_NOTIF_ID); // multiple watch setup if (progresspercent == 100){ scheduleDismissBolusprogress(5); } }
Example 14
Source File: NotificationService.java From Pix-Art-Messenger with GNU General Public License v3.0 | 5 votes |
public void notify(int id, Notification notification) { final NotificationManagerCompat notificationManager = NotificationManagerCompat.from(mXmppConnectionService); try { notificationManager.notify(id, notification); } catch (RuntimeException e) { Log.d(Config.LOGTAG, "unable to make notification", e); } }
Example 15
Source File: NotificationService.java From Pix-Art-Messenger with GNU General Public License v3.0 | 5 votes |
private void cancel(String tag, int id) { final NotificationManagerCompat notificationManager = NotificationManagerCompat.from(mXmppConnectionService); try { notificationManager.cancel(tag, id); } catch (RuntimeException e) { Log.d(Config.LOGTAG, "unable to cancel notification", e); } }
Example 16
Source File: SoundService.java From volume_control_android with MIT License | 5 votes |
@Override public void onCreate() { super.onCreate(); notificationManagerCompat = NotificationManagerCompat.from(this); soundProfileStorage = SoundApplication.getSoundProfileStorage(this); control = SoundApplication.getVolumeControl(this); }
Example 17
Source File: RNPushNotification.java From react-native-push-notification with MIT License | 4 votes |
@ReactMethod public void checkPermissions(Promise promise) { ReactContext reactContext = getReactApplicationContext(); NotificationManagerCompat managerCompat = NotificationManagerCompat.from(reactContext); promise.resolve(managerCompat.areNotificationsEnabled()); }
Example 18
Source File: MessagingIntentService.java From android-Notifications with Apache License 2.0 | 4 votes |
/** Handles action for replying to messages from the notification. */ private void handleActionReply(CharSequence replyCharSequence) { Log.d(TAG, "handleActionReply(): " + replyCharSequence); if (replyCharSequence != null) { // TODO: Asynchronously save your message to Database and servers. /* * You have two options for updating your notification (this class uses approach #2): * * 1. Use a new NotificationCompatBuilder to create the Notification. This approach * requires you to get *ALL* the information that existed in the previous * Notification (and updates) and pass it to the builder. This is the approach used in * the MainActivity. * * 2. Use the original NotificationCompatBuilder to create the Notification. This * approach requires you to store a reference to the original builder. The benefit is * you only need the new/updated information. In our case, the reply from the user * which we already have here. * * IMPORTANT NOTE: You shouldn't save/modify the resulting Notification object using * its member variables and/or legacy APIs. If you want to retain anything from update * to update, retain the Builder as option 2 outlines. */ // Retrieves NotificationCompat.Builder used to create initial Notification NotificationCompat.Builder notificationCompatBuilder = GlobalNotificationBuilder.getNotificationCompatBuilderInstance(); // Recreate builder from persistent state if app process is killed if (notificationCompatBuilder == null) { // Note: New builder set globally in the method notificationCompatBuilder = recreateBuilderWithMessagingStyle(); } // Since we are adding to the MessagingStyle, we need to first retrieve the // current MessagingStyle from the Notification itself. Notification notification = notificationCompatBuilder.build(); MessagingStyle messagingStyle = NotificationCompat.MessagingStyle.extractMessagingStyleFromNotification( notification); // Add new message to the MessagingStyle. Set last parameter to null for responses // from user. messagingStyle.addMessage(replyCharSequence, System.currentTimeMillis(), (Person) null); // Updates the Notification notification = notificationCompatBuilder.setStyle(messagingStyle).build(); // Pushes out the updated Notification NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(getApplicationContext()); notificationManagerCompat.notify(MainActivity.NOTIFICATION_ID, notification); } }
Example 19
Source File: IgnoreBatteryOptimizationNotification.java From PhoneProfilesPlus with Apache License 2.0 | 4 votes |
static private void showNotification(Context context, String title, String text) { String nTitle = title; String nText = text; if (Build.VERSION.SDK_INT < 24) { nTitle = context.getString(R.string.ppp_app_name); nText = title+": "+text; } PPApplication.createExclamationNotificationChannel(context); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, PPApplication.EXCLAMATION_NOTIFICATION_CHANNEL) .setColor(ContextCompat.getColor(context, R.color.notificationDecorationColor)) .setSmallIcon(R.drawable.ic_exclamation_notify) // notification icon .setContentTitle(nTitle) // title for notification .setContentText(nText) // message for notification .setAutoCancel(true); // clear notification after click mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(nText)); Intent intent = new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pi = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(pi); mBuilder.setPriority(NotificationCompat.PRIORITY_MAX); //if (android.os.Build.VERSION.SDK_INT >= 21) //{ mBuilder.setCategory(NotificationCompat.CATEGORY_RECOMMENDATION); mBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC); //} mBuilder.setOnlyAlertOnce(true); /* Intent disableIntent = new Intent(IGNORE_BATTERY_OPTIMIZATION_NOTIFICATION_DISABLE_ACTION); PendingIntent pDisableIntent = PendingIntent.getBroadcast(context, 0, disableIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Action.Builder actionBuilder = new NotificationCompat.Action.Builder( R.drawable.ic_action_exit_app_white, context.getString(R.string.ignore_battery_optimization_notification_disable_button), pDisableIntent); mBuilder.addAction(actionBuilder.build()); */ NotificationManagerCompat mNotificationManager = NotificationManagerCompat.from(context); try { mNotificationManager.notify( PPApplication.IGNORE_BATTERY_OPTIMIZATION_NOTIFICATION_TAG, PPApplication.IGNORE_BATTERY_OPTIMIZATION_NOTIFICATION_ID, mBuilder.build()); } catch (Exception e) { //Log.e("IgnoreBatteryOptimizationNotification.showNotification", Log.getStackTraceString(e)); PPApplication.recordException(e); } }
Example 20
Source File: SocketService.java From zephyr with MIT License | 4 votes |
private void dismissServiceNotification() { NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.cancel(ZephyrNotificationId.SOCKET_SERVICE_STATUS); }