List of usage examples for android.support.v4.app NotificationManagerCompat from
public static NotificationManagerCompat from(Context context)
From source file:com.android.deskclock.alarms.AlarmNotifications.java
public static void showSnoozeNotification(Context context, AlarmInstance instance) { LogUtils.v("Displaying snoozed notification for alarm instance: " + instance.mId); NotificationCompat.Builder notification = new NotificationCompat.Builder(context) .setContentTitle(instance.getLabelOrDefault(context)) .setContentText(context.getString(R.string.alarm_alert_snooze_until, AlarmUtils.getFormattedTime(context, instance.getAlarmTime()))) .setSmallIcon(R.drawable.stat_notify_alarm).setAutoCancel(false).setOngoing(true) .setPriority(NotificationCompat.PRIORITY_MAX).setCategory(NotificationCompat.CATEGORY_ALARM) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC).setLocalOnly(true); // Setup up dismiss action Intent dismissIntent = AlarmStateManager.createStateChangeIntent(context, AlarmStateManager.ALARM_DISMISS_TAG, instance, AlarmInstance.DISMISSED_STATE); notification.addAction(R.drawable.ic_alarm_off_24dp, context.getString(R.string.alarm_alert_dismiss_text), PendingIntent.getService(context, instance.hashCode(), dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT)); // Setup content action if instance is owned by alarm Intent viewAlarmIntent = createViewAlarmIntent(context, instance); notification.setContentIntent(PendingIntent.getActivity(context, instance.hashCode(), viewAlarmIntent, PendingIntent.FLAG_UPDATE_CURRENT)); NotificationManagerCompat nm = NotificationManagerCompat.from(context); nm.notify(instance.hashCode(), notification.build()); }
From source file:com.adkdevelopment.earthquakesurvival.ui.geofence.GeofenceService.java
/** * Sends a notification to the phone/*www .j ava2 s.c om*/ * @param notificationDetails String with details to show in the notification */ private void sendNotification(List<String> notificationDetails) { Context context = getBaseContext(); // Create an explicit content Intent that starts the main Activity. Intent notificationIntent = new Intent(context, DetailActivity.class); notificationIntent.putStringArrayListExtra(Feature.GEOFENCE, (ArrayList<String>) notificationDetails); // Construct a task stack. TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Add the main Activity to the task stack as the parent. stackBuilder.addParentStack(PagerActivity.class); // Push the content Intent onto the stack. stackBuilder.addNextIntent(notificationIntent); // Get a PendingIntent containing the entire back stack. PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Get a notification builder that's compatible with platform versions >= 4 NotificationCompat.Builder builder = new NotificationCompat.Builder(this); Bitmap largeIcon = null; try { largeIcon = Picasso.with(context).load(R.mipmap.ic_launcher).get(); } catch (IOException e) { Log.e(TAG, "e:" + e); } // Define the notification settings. builder.setAutoCancel(true).setSmallIcon(R.mipmap.ic_launcher).setDefaults(Notification.DEFAULT_ALL) .setLargeIcon(largeIcon).setColor(Color.RED).setTicker(getString(R.string.geofence_notification)) .setContentTitle(getString(R.string.app_name)) .setContentText(getString(R.string.geofence_notification_text)) .setContentIntent(notificationPendingIntent) .setStyle(new NotificationCompat.BigTextStyle().bigText( notificationDetails.get(0) + "\n" + getString(R.string.geofence_notification_text))) .setGroup(EarthquakeObject.NOTIFICATION_GROUP); // Get an instance of the Notification manager NotificationManagerCompat mNotificationManager = NotificationManagerCompat.from(context); // Issue the notification mNotificationManager.notify(EarthquakeObject.NOTIFICATION_ID_1, builder.build()); }
From source file:com.ferdi2005.secondgram.NotificationsController.java
public NotificationsController() { notificationManager = NotificationManagerCompat.from(ApplicationLoader.applicationContext); SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Context.MODE_PRIVATE); inChatSoundEnabled = preferences.getBoolean("EnableInChatSound", true); try {/*from w w w . j a v a 2s . c om*/ audioManager = (AudioManager) ApplicationLoader.applicationContext .getSystemService(Context.AUDIO_SERVICE); } catch (Exception e) { FileLog.e(e); } try { alarmManager = (AlarmManager) ApplicationLoader.applicationContext .getSystemService(Context.ALARM_SERVICE); } catch (Exception e) { FileLog.e(e); } try { PowerManager pm = (PowerManager) ApplicationLoader.applicationContext .getSystemService(Context.POWER_SERVICE); notificationDelayWakelock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "lock"); notificationDelayWakelock.setReferenceCounted(false); } catch (Exception e) { FileLog.e(e); } notificationDelayRunnable = new Runnable() { @Override public void run() { FileLog.e("delay reached"); if (!delayedPushMessages.isEmpty()) { showOrUpdateNotification(true); delayedPushMessages.clear(); } try { if (notificationDelayWakelock.isHeld()) { notificationDelayWakelock.release(); } } catch (Exception e) { FileLog.e(e); } } }; }
From source file:com.qiscus.sdk.service.QiscusPusherService.java
private void showPushNotification(QiscusComment comment) { QiscusCacheManager.getInstance().addMessageNotifItem(comment.getMessage(), comment.getRoomId()); Intent openIntent = new Intent("com.qiscus.OPEN_COMMENT_PN"); openIntent.putExtra("data", comment); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, openIntent, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder.setContentTitle(Qiscus.getChatConfig().getNotificationTitleHandler().getTitle(comment)) .setContentIntent(pendingIntent) .setContentText(isAttachment(comment.getMessage()) ? fileMessage : comment.getMessage()) .setTicker(isAttachment(comment.getMessage()) ? fileMessage : comment.getMessage()) .setSmallIcon(Qiscus.getChatConfig().getNotificationSmallIcon()) .setLargeIcon(BitmapFactory.decodeResource(getResources(), Qiscus.getChatConfig().getNotificationBigIcon())) .setGroupSummary(true).setGroup("CHAT_NOTIF_" + comment.getRoomId()).setAutoCancel(true) .setDefaults(Notification.DEFAULT_ALL); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); List<String> notifItems = QiscusCacheManager.getInstance().getMessageNotifItems(comment.getRoomId()); for (String message : notifItems) { if (isAttachment(message)) { inboxStyle.addLine(fileMessage); } else {//w w w . j a v a 2 s.c om inboxStyle.addLine(message); } } inboxStyle.setSummaryText(notifItems.size() + " new message"); notificationBuilder.setStyle(inboxStyle); NotificationManagerCompat.from(this).notify(comment.getRoomId(), notificationBuilder.build()); }
From source file:com.near.chimerarevo.services.NewsService.java
private void createNotification() { if (!PreferenceManager.getDefaultSharedPreferences(this).getBoolean("notification_pref", true)) return;/*from w w w .j a v a2 s. c om*/ Intent intent = new Intent(this, MainActivity.class); PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0); NotificationCompat.BigTextStyle bigStyle = new NotificationCompat.BigTextStyle(); bigStyle.bigText(getResources().getString(R.string.text_newposts_summary)); bigStyle.setBigContentTitle(getResources().getString(R.string.app_name)); NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender() .setContentIcon(R.drawable.ic_logo_cr_mini).setHintHideIcon(true); Notification n = new NotificationCompat.Builder(this) .setContentTitle(getResources().getString(R.string.app_name)) .setContentText(getResources().getString(R.string.text_newposts_summary)) .setSmallIcon(R.drawable.ic_logo_cr_mini).setContentIntent(pIntent).extend(wearableExtender) .setAutoCancel(true).build(); if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("notification_vibrate_pref", true)) n.defaults |= Notification.DEFAULT_VIBRATE; if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("notification_sound_pref", true)) n.defaults |= Notification.DEFAULT_SOUND; if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("notification_light_pref", true)) { n.ledARGB = getLEDColor(); n.ledOnMS = 300; n.ledOffMS = 1000; n.flags |= Notification.FLAG_SHOW_LIGHTS; } NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(0, n); }
From source file:com.stasbar.knowyourself.alarms.AlarmNotifications.java
public static void showHighPriorityNotification(Context context, AlarmInstance instance) { LogUtils.v("Displaying high priority notification for alarm instance: " + instance.mId); NotificationCompat.Builder notification = new NotificationCompat.Builder(context).setShowWhen(false) .setContentTitle(context.getString(R.string.alarm_alert_predismiss_title)) .setContentText(AlarmUtils.getAlarmText(context, instance, true /* includeLabel */)) .setColor(ContextCompat.getColor(context, R.color.default_background)) .setSmallIcon(R.drawable.stat_notify_alarm).setAutoCancel(false).setSortKey(createSortKey(instance)) .setPriority(NotificationCompat.PRIORITY_HIGH).setCategory(NotificationCompat.CATEGORY_ALARM) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC).setLocalOnly(true); if (Utils.isNOrLater()) { notification.setGroup(UPCOMING_GROUP_KEY); }/* ww w . j ava2s.c o m*/ // Setup up dismiss action Intent dismissIntent = AlarmStateManager.createStateChangeIntent(context, AlarmStateManager.ALARM_DISMISS_TAG, instance, AlarmInstance.PREDISMISSED_STATE); notification.addAction(R.drawable.ic_alarm_off_24dp, context.getString(R.string.alarm_alert_dismiss_now_text), PendingIntent.getService(context, instance.hashCode(), dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT)); // Setup content action if instance is owned by alarm Intent viewAlarmIntent = createViewAlarmIntent(context, instance); notification.setContentIntent(PendingIntent.getActivity(context, instance.hashCode(), viewAlarmIntent, PendingIntent.FLAG_UPDATE_CURRENT)); NotificationManagerCompat nm = NotificationManagerCompat.from(context); nm.notify(instance.hashCode(), notification.build()); updateAlarmGroupNotification(context); }
From source file:org.chromium.tools.audio_focus_grabber.AudioFocusGrabberListenerService.java
private void hideNotification() { NotificationManagerCompat manager = NotificationManagerCompat.from(this); manager.cancel(NOTIFICATION_ID); }
From source file:com.rickendirk.rsgwijzigingen.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);//from w w w. jav a 2 s. c o m viewPager = (ViewPager) findViewById(R.id.viewPager); setupViewPager(); animDuration = getResources().getInteger(android.R.integer.config_longAnimTime); TabLayout tabLayout = (TabLayout) findViewById(R.id.tabLayout); tabLayout.setupWithViewPager(viewPager); setTitle("Roosterwijzigingen"); final FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); final ViewPagerAdapter adapter = (ViewPagerAdapter) viewPager.getAdapter(); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { int itemID = viewPager.getCurrentItem(); if (itemID == 0) { //Persoonlijke pagina, dus checken MainFragment mainFragment = (MainFragment) adapter.getItem(itemID); mainFragment.checker(); } if (itemID == 1) { //Algemeen, dus pagina vernieuwen WebFragment webFragment = (WebFragment) adapter.getItem(itemID); webFragment.refresh(); } } }); viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageSelected(int position) { if (position == 1) {//webview fragment WebFragment webFragment = (WebFragment) adapter.getItem(position); boolean isFinished = webFragment.isFinished(); boolean isLoading = webFragment.isLoading(); if (!isLoading && !isFinished) { webFragment.refresh(); } fab.hide(); tracker.send(new HitBuilders.EventBuilder().setCategory("Navigatie") .setAction("naar_webFragment").build()); } else { //Gewone fragment, dus toolbar moet weer bovenaan gaan staan AppBarLayout appbar = (AppBarLayout) findViewById(R.id.appBarLayout); appbar.setExpanded(true, true); fab.show(); tracker.send(new HitBuilders.EventBuilder().setCategory("Navigatie") .setAction("naar_mainFragment").build()); } } @Override public void onPageScrollStateChanged(int state) { } }); check1ekeer(); OwnApplication application = (OwnApplication) getApplication(); tracker = application.getDefaultTracker(); tracker.setScreenName("onCreate_MainAcitivity"); tracker.send(new HitBuilders.ScreenViewBuilder().build()); Intent ownIntent = getIntent(); boolean isVanNotificatie = ownIntent.getBooleanExtra("isVanNotificatie", false); if (isVanNotificatie) { NotificationManagerCompat manager = NotificationManagerCompat.from(this); manager.cancel(ZoekService.notifID); } prepareWarmCustomTab(); }
From source file:at.bitfire.davdroid.AccountSettings.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) public AccountSettings(@NonNull Context context, @NonNull Account account) throws InvalidAccountException { this.context = context; this.account = account; accountManager = AccountManager.get(context); synchronized (AccountSettings.class) { String versionStr = accountManager.getUserData(account, KEY_SETTINGS_VERSION); if (versionStr == null) throw new InvalidAccountException(account); int version = 0; try {//from www. j av a2 s .c o m version = Integer.parseInt(versionStr); } catch (NumberFormatException ignored) { } App.log.info("Account " + account.name + " has version " + version + ", current version: " + CURRENT_VERSION); if (version < CURRENT_VERSION) { Notification notify = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_new_releases_light).setLargeIcon(App.getLauncherBitmap(context)) .setContentTitle(context.getString(R.string.settings_version_update)) .setContentText(context.getString(R.string.settings_version_update_settings_updated)) .setSubText(context.getString(R.string.settings_version_update_install_hint)) .setStyle(new NotificationCompat.BigTextStyle() .bigText(context.getString(R.string.settings_version_update_settings_updated))) .setCategory(NotificationCompat.CATEGORY_SYSTEM) .setPriority(NotificationCompat.PRIORITY_HIGH) .setContentIntent(PendingIntent.getActivity(context, 0, new Intent(Intent.ACTION_VIEW, Constants.webUri.buildUpon() .appendEncodedPath("faq/entry/davdroid-not-working-after-update/").build()), PendingIntent.FLAG_CANCEL_CURRENT)) .setLocalOnly(true).build(); NotificationManagerCompat nm = NotificationManagerCompat.from(context); nm.notify(Constants.NOTIFICATION_ACCOUNT_SETTINGS_UPDATED, notify); update(version); } } }
From source file:com.zuluindia.watchpresenter.MonitorVolumeKeyPress.java
private synchronized void scheduleMaintenance() { if (timer != null) { timer.cancel();/*from w w w . j a v a2 s. c o m*/ } timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { if (MainActivity.active == false) { Log.d(Constants.LOG_TAG, "Timeout, stopping keypress monitoring service..."); NotificationManagerCompat notificationManager = NotificationManagerCompat .from(MonitorVolumeKeyPress.this); // Build the notification and issues it with notification manager. notificationManager.cancel(MainActivity.PRESENTING_NOTIFICATION_ID); (new WearController(MonitorVolumeKeyPress.this)).stopGestureDetection(); stopSelf(); } else { Log.d(Constants.LOG_TAG, "Timeout, but MainActivity in foreground. Not stopping"); } } }, SWITCH_OFF_DELAY); timer.schedule(new TimerTask() { @Override public void run() { Intent i = new Intent(SendMessageReceiver.INTENT); i.putExtra(Constants.EXTRA_MESSAGE, Constants.WARMUP_MESSAGE); sendBroadcast(i); } }, KEEP_ALIVE_PERIOD, KEEP_ALIVE_PERIOD); }