List of usage examples for android.app Notification PRIORITY_LOW
int PRIORITY_LOW
To view the source code for android.app Notification PRIORITY_LOW.
Click Source Link
From source file:net.frakbot.FWeather.util.FeedbackService.java
@Override protected void onHandleIntent(Intent intent) { FLog.d(TAG, "Handling 'send feedback' intent"); NotificationCompat.Builder b = new NotificationCompat.Builder(this); b.setProgress(100, 0, true).setOngoing(true).setPriority(Notification.PRIORITY_LOW) .setContentTitle(getString(R.string.preparing_feedback)) .setTicker(getString(R.string.preparing_feedback)); startForeground(NOTIF_ID_FEEDBACK, b.build()); if (isInstalledFromPlayStore() && canSendPlayStoreFeedback()) { sendNativeFeedback();/*w w w . j a va2 s . co m*/ } else { // Use the fallback "share" mechanism sendFeedbackEmail(); } }
From source file:butter.droid.base.torrent.TorrentService.java
public void startForeground() { if (Foreground.get().isForeground()) return;/*from ww w . j av a 2 s. c o m*/ if (mCurrentActivityClass == null) return; Intent notificationIntent = new Intent(this, mCurrentActivityClass); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); Intent stopIntent = new Intent(); stopIntent.setAction(TorrentBroadcastReceiver.STOP); PendingIntent pendingStopIntent = PendingIntent.getBroadcast(this, TorrentBroadcastReceiver.REQUEST_CODE, stopIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Action stopAction = new NotificationCompat.Action.Builder( R.drawable.abc_ic_clear_mtrl_alpha, getString(R.string.stop), pendingStopIntent).build(); NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_notif_logo) .setContentTitle(getString(R.string.app_name) + " - " + getString(R.string.running)) .setContentText(getString(R.string.tap_to_resume)).setOngoing(true).setOnlyAlertOnce(true) .setPriority(Notification.PRIORITY_LOW).setContentIntent(pendingIntent).addAction(stopAction) .setCategory(NotificationCompat.CATEGORY_SERVICE); if (mStreamStatus != null && mIsReady) { String downloadSpeed; DecimalFormat df = new DecimalFormat("#############0.00"); if (mStreamStatus.downloadSpeed / 1024 < 1000) { downloadSpeed = df.format(mStreamStatus.downloadSpeed / 1024) + " KB/s"; } else { downloadSpeed = df.format(mStreamStatus.downloadSpeed / (1024 * 1024)) + " MB/s"; } String progress = df.format(mStreamStatus.progress); builder.setContentText(progress + "%, " + downloadSpeed); } Notification notification = builder.build(); NotificationManager notifManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notifManager.notify(NOTIFICATION_ID, notification); startForeground(NOTIFICATION_ID, notification); if (mUpdateTimer == null) { mUpdateTimer = new Timer(); mUpdateTimer.scheduleAtFixedRate(new UpdateTask(), 5000, 5000); } }
From source file:net.networksaremadeofstring.rhybudd.Notifications.java
public static void SendGCMNotification(ZenossEvent Event, Context context) { SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context); Time now = new Time(); now.setToNow();// w w w .j a v a 2s. c o m //We don't need to overwhelm the user with their notification sound / vibrator if ((now.toMillis(true) - PreferenceManager.getDefaultSharedPreferences(context).getLong("lastCheck", now.toMillis(true))) < 3000) { //Log.e("SendGCMNotification", "Not publishing a notification due to stampede control"); return; } Intent notificationIntent = new Intent(context, ViewZenossEventsListActivity.class); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); notificationIntent.putExtra("forceRefresh", true); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); Uri soundURI = null; try { if (settings.getBoolean("notificationSound", true)) { if (settings.getString("notificationSoundChoice", "").equals("")) { soundURI = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); } else { try { soundURI = Uri.parse(settings.getString("notificationSoundChoice", "")); } catch (Exception e) { soundURI = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); } } } else { soundURI = null; } } catch (Exception e) { } String notifTitle = "New Events Received"; int notifPriority = Notification.PRIORITY_DEFAULT; //int AlertType = NOTIFICATION_GCM_GENERIC; try { if (Event.getSeverity().equals("5")) { notifTitle = context.getString(R.string.CriticalNotificationTitle); notifPriority = Notification.PRIORITY_MAX; //AlertType = NOTIFICATION_GCM_CRITICAL; } else if (Event.getSeverity().equals("4")) { notifTitle = context.getString(R.string.ErrorNotificationTitle); notifPriority = Notification.PRIORITY_HIGH; //AlertType = NOTIFICATION_GCM_ERROR; } else if (Event.getSeverity().equals("3")) { notifTitle = context.getString(R.string.WarnNotificationTitle); notifPriority = Notification.PRIORITY_DEFAULT; //AlertType = NOTIFICATION_GCM_WARNING; } else if (Event.getSeverity().equals("2")) { notifTitle = context.getString(R.string.InfoNotificationTitle); notifPriority = Notification.PRIORITY_LOW; //AlertType = NOTIFICATION_GCM_INFO; } else if (Event.getSeverity().equals("1")) { notifTitle = context.getString(R.string.DebugNotificationTitle); notifPriority = Notification.PRIORITY_MIN; //AlertType = NOTIFICATION_GCM_DEBUG; } } catch (Exception e) { } long[] vibrate = { 0, 100, 200, 300 }; try { AudioManager audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); //Log.e("audio.getRingerMode()",Integer.toString(audio.getRingerMode())); switch (audio.getRingerMode()) { case AudioManager.RINGER_MODE_SILENT: //Do nothing to fix GitHub issue #13 //Log.e("AudioManager","Doing nothing because we are silent"); vibrate = new long[] { 0, 0 }; break; } } catch (Exception e) { e.printStackTrace(); } Intent broadcastMassAck = new Intent(); broadcastMassAck.setAction(MassAcknowledgeReceiver.BROADCAST_ACTION); PendingIntent pBroadcastMassAck = PendingIntent.getBroadcast(context, 0, broadcastMassAck, 0); if (Build.VERSION.SDK_INT >= 16) { Notification noti = new Notification.BigTextStyle(new Notification.Builder(context) .setContentTitle(notifTitle).setPriority(notifPriority).setAutoCancel(true).setSound(soundURI) .setVibrate(vibrate).setContentText(Event.getDevice()).setContentIntent(contentIntent) .addAction(R.drawable.ic_action_resolve_all, "Acknowledge all Events", pBroadcastMassAck) .setSmallIcon(R.drawable.ic_stat_alert)).bigText( Event.getSummary() + "\r\n" + Event.getComponentText() + "\r\n" + Event.geteventClass()) .build(); if (settings.getBoolean("notificationSoundInsistent", false)) noti.flags |= Notification.FLAG_INSISTENT; noti.tickerText = notifTitle; NotificationManager mNM = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); mNM.notify(NOTIFICATION_GCM_GENERIC, noti); } else { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_stat_alert).setContentTitle(notifTitle) .setContentText(Event.getDevice() + ": " + Event.getSummary()).setContentIntent(contentIntent) .setSound(soundURI).setVibrate(vibrate) .addAction(R.drawable.ic_action_resolve_all, "Acknowledge all Events", pBroadcastMassAck) .setAutoCancel(true).setPriority(notifPriority); NotificationManager mNM = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); mNM.notify(NOTIFICATION_GCM_GENERIC, mBuilder.build()); } }
From source file:us.alerted.alerted.LocationService.java
protected static void postNotification(Intent intentAction, Context context) { List<Alert> alerts = Alert.find(Alert.class, null, null, null, "effective DESC", "1"); Map<String, Integer> categoryLookup = new HashMap<>(); {/*ww w. j a v a 2s. c o m*/ categoryLookup.put("Geo", R.drawable.geo); categoryLookup.put("Met", R.drawable.met); categoryLookup.put("Safety", R.drawable.safety); categoryLookup.put("Security", R.drawable.security); categoryLookup.put("Rescue", R.drawable.rescue); categoryLookup.put("Fire", R.drawable.fire); categoryLookup.put("Health", R.drawable.health); categoryLookup.put("Env", R.drawable.env); categoryLookup.put("Transport", R.drawable.transport); categoryLookup.put("Infra", R.drawable.infra); categoryLookup.put("CBRNE", R.drawable.cbrne); categoryLookup.put("Other", R.drawable.other); } Map<String, Integer> severityLookup = new HashMap<>(); { severityLookup.put("Extreme", Notification.PRIORITY_HIGH); severityLookup.put("Severe", Notification.PRIORITY_LOW); severityLookup.put("Moderate", Notification.PRIORITY_MIN); severityLookup.put("Minor", Notification.PRIORITY_MIN); severityLookup.put("Unknown", Notification.PRIORITY_MIN); } if (alerts.size() > 0) { String msg = alerts.get(0).event; final NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); final Integer desc_cap_category = categoryLookup.get(alerts.get(0).category); final Integer notif_priority = severityLookup.get(alerts.get(0).severity); final PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intentAction, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_CANCEL_CURRENT); final Notification notification = new NotificationCompat.Builder(context) .setSmallIcon(desc_cap_category).setContentTitle(msg).setContentText("") .setContentIntent(pendingIntent).setAutoCancel(true).setPriority(notif_priority) .getNotification(); mNotificationManager.notify(R.string.notification_number, notification); } }
From source file:at.bitfire.davdroid.syncadapter.DavSyncAdapter.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) @Override// w ww. j a va 2 s.c o m public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { Log.i(TAG, "Performing sync for authority " + authority); /* Set class loader for iCal4j ResourceLoader this is required because the various * sync adapters (contacts, events, tasks) share the same :sync process (see AndroidManifest */ Thread.currentThread().setContextClassLoader(getContext().getClassLoader()); // create httpClient, if necessary httpClientLock.writeLock().lock(); if (httpClient == null) { Log.d(TAG, "Creating new DavHttpClient"); httpClient = DavHttpClient.create(); } // prevent httpClient shutdown until we're ready by holding a read lock // acquiring read lock before releasing write lock will downgrade the write lock to a read lock httpClientLock.readLock().lock(); httpClientLock.writeLock().unlock(); Exception exceptionToShow = null; // exception to show notification for Intent exceptionIntent = null; // what shall happen when clicking on the exception notification try { // get local <-> remote collection pairs Map<LocalCollection<?>, WebDavCollection<?>> syncCollections = getSyncPairs(account, provider); if (syncCollections == null) Log.i(TAG, "Nothing to synchronize"); else try { for (Map.Entry<LocalCollection<?>, WebDavCollection<?>> entry : syncCollections.entrySet()) new SyncManager(entry.getKey(), entry.getValue()) .synchronize(extras.containsKey(ContentResolver.SYNC_EXTRAS_MANUAL), syncResult); } catch (DavException ex) { syncResult.stats.numParseExceptions++; Log.e(TAG, "Invalid DAV response", ex); exceptionToShow = ex; } catch (HttpException ex) { if (ex.getCode() == HttpStatus.SC_UNAUTHORIZED) { Log.e(TAG, "HTTP Unauthorized " + ex.getCode(), ex); syncResult.stats.numAuthExceptions++; // hard error exceptionToShow = ex; exceptionIntent = new Intent(context, AccountActivity.class); exceptionIntent.putExtra(AccountActivity.EXTRA_ACCOUNT, account); } else if (ex.isClientError()) { Log.e(TAG, "Hard HTTP error " + ex.getCode(), ex); syncResult.stats.numParseExceptions++; // hard error exceptionToShow = ex; } else { Log.w(TAG, "Soft HTTP error " + ex.getCode() + " (Android will try again later)", ex); syncResult.stats.numIoExceptions++; // soft error } } catch (LocalStorageException ex) { syncResult.databaseError = true; // hard error Log.e(TAG, "Local storage (content provider) exception", ex); exceptionToShow = ex; } catch (IOException ex) { syncResult.stats.numIoExceptions++; // soft error Log.e(TAG, "I/O error (Android will try again later)", ex); if (ex instanceof SSLException) // always notify on SSL/TLS errors exceptionToShow = ex; } catch (URISyntaxException ex) { syncResult.stats.numParseExceptions++; // hard error Log.e(TAG, "Invalid URI (file name) syntax", ex); exceptionToShow = ex; } } finally { // allow httpClient shutdown httpClientLock.readLock().unlock(); } // show sync errors as notification if (exceptionToShow != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { if (exceptionIntent == null) exceptionIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.WEB_URL_VIEW_LOGS)); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, exceptionIntent, 0); Notification.Builder builder = new Notification.Builder(context).setSmallIcon(R.drawable.ic_launcher) .setPriority(Notification.PRIORITY_LOW).setOnlyAlertOnce(true) .setWhen(System.currentTimeMillis()) .setContentTitle(context.getString(R.string.sync_error_title)) .setContentText(exceptionToShow.getLocalizedMessage()).setContentInfo(account.name) .setStyle(new Notification.BigTextStyle() .bigText(account.name + ":\n" + ExceptionUtils.getStackTrace(exceptionToShow))) .setContentIntent(contentIntent); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(account.name.hashCode(), builder.build()); } Log.i(TAG, "Sync complete for " + authority); }
From source file:com.granita.icloudcalsync.syncadapter.DavSyncAdapter.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) @Override/*from www. jav a 2 s . com*/ public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { Log.i(TAG, "Performing sync for authority " + authority); // set class loader for iCal4j ResourceLoader Thread.currentThread().setContextClassLoader(getContext().getClassLoader()); // create httpClient, if necessary httpClientLock.writeLock().lock(); if (httpClient == null) { Log.d(TAG, "Creating new DavHttpClient"); SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getContext()); httpClient = DavHttpClient.create(); } // prevent httpClient shutdown until we're ready by holding a read lock // acquiring read lock before releasing write lock will downgrade the write lock to a read lock httpClientLock.readLock().lock(); httpClientLock.writeLock().unlock(); // TODO use VCard 4.0 if possible AccountSettings accountSettings = new AccountSettings(getContext(), account); Log.d(TAG, "Server supports VCard version " + accountSettings.getAddressBookVCardVersion()); Exception exceptionToShow = null; // exception to show notification for Intent exceptionIntent = null; // what shall happen when clicking on the exception notification try { // get local <-> remote collection pairs Map<LocalCollection<?>, RemoteCollection<?>> syncCollections = getSyncPairs(account, provider); if (syncCollections == null) Log.i(TAG, "Nothing to synchronize"); else try { for (Map.Entry<LocalCollection<?>, RemoteCollection<?>> entry : syncCollections.entrySet()) new SyncManager(entry.getKey(), entry.getValue()) .synchronize(extras.containsKey(ContentResolver.SYNC_EXTRAS_MANUAL), syncResult); } catch (DavException ex) { syncResult.stats.numParseExceptions++; Log.e(TAG, "Invalid DAV response", ex); exceptionToShow = ex; } catch (HttpException ex) { if (ex.getCode() == HttpStatus.SC_UNAUTHORIZED) { Log.e(TAG, "HTTP Unauthorized " + ex.getCode(), ex); syncResult.stats.numAuthExceptions++; // hard error exceptionToShow = ex; exceptionIntent = new Intent(context, AccountActivity.class); exceptionIntent.putExtra(AccountActivity.EXTRA_ACCOUNT, account); } else if (ex.isClientError()) { Log.e(TAG, "Hard HTTP error " + ex.getCode(), ex); syncResult.stats.numParseExceptions++; // hard error exceptionToShow = ex; } else { Log.w(TAG, "Soft HTTP error " + ex.getCode() + " (Android will try again later)", ex); syncResult.stats.numIoExceptions++; // soft error } } catch (LocalStorageException ex) { syncResult.databaseError = true; // hard error Log.e(TAG, "Local storage (content provider) exception", ex); exceptionToShow = ex; } catch (IOException ex) { syncResult.stats.numIoExceptions++; // soft error Log.e(TAG, "I/O error (Android will try again later)", ex); if (ex instanceof SSLException) // always notify on SSL/TLS errors exceptionToShow = ex; } catch (URISyntaxException ex) { syncResult.stats.numParseExceptions++; // hard error Log.e(TAG, "Invalid URI (file name) syntax", ex); exceptionToShow = ex; } } finally { // allow httpClient shutdown httpClientLock.readLock().unlock(); } // show sync errors as notification if (exceptionToShow != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { if (exceptionIntent == null) exceptionIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.WEB_URL_VIEW_LOGS)); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, exceptionIntent, 0); Notification.Builder builder = new Notification.Builder(context).setSmallIcon(R.drawable.ic_launcher) .setPriority(Notification.PRIORITY_LOW).setOnlyAlertOnce(true) .setWhen(System.currentTimeMillis()) .setContentTitle(context.getString(R.string.sync_error_title)) .setContentText(exceptionToShow.getLocalizedMessage()).setContentInfo(account.name) .setStyle(new Notification.BigTextStyle() .bigText(account.name + ":\n" + ExceptionUtils.getFullStackTrace(exceptionToShow))) .setContentIntent(contentIntent); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(account.name.hashCode(), builder.build()); } Log.i(TAG, "Sync complete for " + authority); }
From source file:com.metinkale.prayerapp.vakit.WidgetService.java
public static void updateOngoing() { extractColors();/*from w w w.j a v a 2s . co m*/ NotificationManager nm = (NotificationManager) App.getContext() .getSystemService(Context.NOTIFICATION_SERVICE); for (int i = mOngoing.size() - 1; i >= 0; i--) { long id = mOngoing.get(i); Times t = Times.getTimes(id); if ((t == null) || !t.isOngoingNotificationActive()) { nm.cancel(id + "", NotIds.ONGOING); mOngoing.remove(i); } } List<Long> ids = Times.getIds(); for (long id : ids) { Times t = Times.getTimes(id); if ((t != null) && t.isOngoingNotificationActive() && !mOngoing.contains(id)) { mOngoing.add(id); } } LocalDate cal = LocalDate.now(); String[] left_part = App.getContext().getResources().getStringArray(R.array.lefttext_part); for (long id : mOngoing) { Times t = Times.getTimes(id); String[] dt = { t.getTime(cal, 0), t.getTime(cal, 1), t.getTime(cal, 2), t.getTime(cal, 3), t.getTime(cal, 4), t.getTime(cal, 5) }; boolean icon = Prefs.showOngoingIcon(); boolean number = Prefs.showOngoingNumber(); Crashlytics.setBool("showIcon", icon); Crashlytics.setBool("showNumber", number); Notification noti; if (Prefs.getAlternativeOngoing()) { RemoteViews views = new RemoteViews(App.getContext().getPackageName(), R.layout.notification_layout); int[] timeIds = { R.id.time0, R.id.time1, R.id.time2, R.id.time3, R.id.time4, R.id.time5 }; int[] vakitIds = { R.id.imsak, R.id.gunes, R.id.ogle, R.id.ikindi, R.id.aksam, R.id.yatsi }; int next = t.getNext(); if (Prefs.getVakitIndicator().equals("next")) next++; for (int i = 0; i < dt.length; i++) { if ((next - 1) == i) { views.setTextViewText(timeIds[i], Html.fromHtml("<strong><em>" + Utils.fixTime(dt[i]) + "</em></strong>")); } else { views.setTextViewText(timeIds[i], Utils.fixTime(dt[i])); } } for (int i = 0; i < dt.length; i++) { if ((next - 1) == i) { views.setTextViewText(vakitIds[i], Html.fromHtml("<strong><em>" + Vakit.getByIndex(i).getString() + "</em></strong>")); } else { views.setTextViewText(vakitIds[i], Vakit.getByIndex(i).getString()); } } views.setTextViewText(R.id.time, t.getLeft(t.getNext(), false)); views.setTextViewText(R.id.city, t.getName()); views.setTextColor(R.id.imsak, COLOR_1ST); views.setTextColor(R.id.gunes, COLOR_1ST); views.setTextColor(R.id.ogle, COLOR_1ST); views.setTextColor(R.id.ikindi, COLOR_1ST); views.setTextColor(R.id.aksam, COLOR_1ST); views.setTextColor(R.id.yatsi, COLOR_1ST); views.setTextColor(R.id.time0, COLOR_1ST); views.setTextColor(R.id.time1, COLOR_1ST); views.setTextColor(R.id.time2, COLOR_1ST); views.setTextColor(R.id.time3, COLOR_1ST); views.setTextColor(R.id.time4, COLOR_1ST); views.setTextColor(R.id.time5, COLOR_1ST); views.setTextColor(R.id.time, COLOR_1ST); views.setTextColor(R.id.city, COLOR_1ST); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { long left = t.getLeftMinutes(t.getNext()); noti = new Notification.Builder(App.getContext()).setContent(views) .setContentIntent(Main.getPendingIntent(t)) .setSmallIcon(icon ? (number ? Icon.createWithBitmap(getIconFromMinutes(left)) : Icon.createWithResource(App.getContext(), R.drawable.ic_abicon)) : Icon.createWithResource(App.getContext(), R.drawable.ic_placeholder)) .setOngoing(true).build(); } else { noti = new NotificationCompat.Builder(App.getContext()).setContent(views) .setContentIntent(Main.getPendingIntent(t)) .setSmallIcon(icon ? R.drawable.ic_abicon : R.drawable.ic_placeholder).setOngoing(true) .build(); } } else { int n = t.getNext(); String sum = App.getContext().getString(R.string.leftText, Vakit.getByIndex(n - 1).getString(), left_part[n], t.getLeft().substring(0, 5)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { long left = t.getLeftMinutes(t.getNext()); noti = new Notification.InboxStyle( new Notification.Builder(App.getContext()) .setContentTitle(t.getName() + " (" + t.getSource() + ")").setContentText("") .setLargeIcon(mAbIcon) .setSmallIcon(icon ? (number ? Icon.createWithBitmap(getIconFromMinutes(left)) : Icon.createWithResource(App.getContext(), R.drawable.ic_abicon)) : Icon.createWithResource(App.getContext(), R.drawable.ic_placeholder)) .setContentInfo(sum).setContentIntent(Main.getPendingIntent(t)) .setOngoing(true)) .addLine(Vakit.getByIndex(0).getString() + ": " + Utils.fixTime(dt[0])) .addLine(Vakit.GUNES.getString() + ": " + Utils.fixTime(dt[1])) .addLine(Vakit.OGLE.getString() + ": " + Utils.fixTime(dt[2])) .addLine(Vakit.IKINDI.getString() + ": " + Utils.fixTime(dt[3])) .addLine(Vakit.AKSAM.getString() + ": " + Utils.fixTime(dt[4])) .addLine(Vakit.YATSI.getString() + ": " + Utils.fixTime(dt[5])) .setSummaryText("").build(); } else { noti = new NotificationCompat.InboxStyle(new NotificationCompat.Builder(App.getContext()) .setContentTitle(t.getName() + " (" + t.getSource() + ")").setContentText("") .setLargeIcon(mAbIcon) .setSmallIcon(icon ? R.drawable.ic_abicon : R.drawable.ic_placeholder) .setContentInfo(sum).setContentIntent(Main.getPendingIntent(t)).setOngoing(true)) .addLine(Vakit.getByIndex(0).getString() + ": " + Utils.fixTime(dt[0])) .addLine(Vakit.GUNES.getString() + ": " + Utils.fixTime(dt[1])) .addLine(Vakit.OGLE.getString() + ": " + Utils.fixTime(dt[2])) .addLine(Vakit.IKINDI.getString() + ": " + Utils.fixTime(dt[3])) .addLine(Vakit.AKSAM.getString() + ": " + Utils.fixTime(dt[4])) .addLine(Vakit.YATSI.getString() + ": " + Utils.fixTime(dt[5])) .setSummaryText("").build(); } } if (Build.VERSION.SDK_INT >= 16) { noti.priority = Notification.PRIORITY_LOW; } noti.when = icon ? System.currentTimeMillis() : 0; try { nm.notify(id + "", NotIds.ONGOING, noti); } catch (Exception e) { Crashlytics.logException(e); } } }
From source file:com.android.madpausa.cardnotificationviewer.ConcreteNotificationListenerService.java
/** * sends the service notification//from w w w .j a v a 2 s.c o m */ private void handleServiceNotification() { NotificationManager nManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); //filtering archived notification list List<StatusBarNotification> filteredArchivedNotificationList = baseNotificationFilter .applyFilter(archivedNotificationMap.values(), notificationGroups, true); int filteredArchiveddSize = filteredArchivedNotificationList.size(); //should show notification only if there are notifications to be shown if (filteredArchiveddSize > 0) { NotificationCompat.Builder nBuilder = new NotificationCompat.Builder(this); nBuilder.setContentTitle( String.format(getString(R.string.service_notification_text), filteredArchiveddSize)); nBuilder.setSmallIcon(R.drawable.ic_notification); //gets the correct color resource, based on android version if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) nBuilder.setColor(getResources().getColor(R.color.app_background, null)); else //noinspection deprecation nBuilder.setColor(getResources().getColor(R.color.app_background)); //setting the intent Intent resultIntent = new Intent(this, MainActivity.class); //setting the extra containing the archived notifications resultIntent.putExtra(ARCHIVED_NOTIFICATIONS_EXTRA, new HashSet<>(archivedNotificationMap.keySet())); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); nBuilder.setContentIntent(resultPendingIntent); //low priority, not min, as it has to show in the lockscreen nBuilder.setPriority(Notification.PRIORITY_LOW); Notification notification = nBuilder.build(); //this notification should be sticky notification.flags |= Notification.FLAG_NO_CLEAR; nManager.notify(SERVICE_NOTIFICATION, 0, notification); } //else I should remove the notification else nManager.cancel(SERVICE_NOTIFICATION, 0); }
From source file:net.networksaremadeofstring.rhybudd.Notifications.java
public static void SendStickyNotification(Context context) { try {/*from w w w. ja va 2s.c o m*/ Calendar date = Calendar.getInstance(); String strDate = ""; if (date.get(Calendar.MINUTE) < 10) { strDate = Integer.toString(date.get(Calendar.HOUR_OF_DAY)) + ":0" + Integer.toString(date.get(Calendar.MINUTE)); } else { strDate = date.get(Calendar.HOUR_OF_DAY) + ":" + date.get(Calendar.MINUTE); } Intent notificationIntent = new Intent(context, ViewZenossEventsListActivity.class); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); notificationIntent.putExtra("forceRefresh", true); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_stat_polling) .setContentTitle("Rhybudd is actively polling for events") .setContentText("Last query: " + strDate + " (Moving to Rhybudd Push would reduce battery drain & data usage)") .setOngoing(true).setOnlyAlertOnce(true).setContentIntent(contentIntent) .setPriority(Notification.PRIORITY_LOW); NotificationManager mNM = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); mNM.notify(NOTIFICATION_POLLED_STICKY, mBuilder.build()); } catch (Exception e) { } }
From source file:com.google.samples.apps.sergio.service.SessionAlarmService.java
private void notifySessionFeedback(boolean debug) { LOGD(TAG, "Considering firing notification for session feedback."); if (debug) {// w ww . j a v a2s. c om LOGD(TAG, "Note: this is a debug notification."); } // Don't fire notification if this feature is disabled in settings if (!PrefUtils.shouldShowSessionFeedbackReminders(this)) { LOGD(TAG, "Skipping session feedback notification. Disabled in settings."); return; } final Cursor c = getContentResolver().query(ScheduleContract.Sessions.CONTENT_MY_SCHEDULE_URI, SessionsNeedingFeedbackQuery.PROJECTION, SessionsNeedingFeedbackQuery.WHERE_CLAUSE, null, null); if (c == null) { return; } List<String> needFeedbackIds = new ArrayList<String>(); List<String> needFeedbackTitles = new ArrayList<String>(); while (c.moveToNext()) { String sessionId = c.getString(SessionsNeedingFeedbackQuery.SESSION_ID); String sessionTitle = c.getString(SessionsNeedingFeedbackQuery.SESSION_TITLE); // Avoid repeated notifications. if (UIUtils.isFeedbackNotificationFiredForSession(this, sessionId)) { LOGD(TAG, "Skipping repeated session feedback notification for session '" + sessionTitle + "'"); continue; } needFeedbackIds.add(sessionId); needFeedbackTitles.add(sessionTitle); } if (needFeedbackIds.size() == 0) { // the user has already been notified of all sessions needing feedback return; } LOGD(TAG, "Going forward with session feedback notification for " + needFeedbackIds.size() + " session(s)."); final Resources res = getResources(); // this is used to synchronize deletion of notifications on phone and wear Intent dismissalIntent = new Intent(ACTION_NOTIFICATION_DISMISSAL); // TODO: fix Wear dismiss integration //dismissalIntent.putExtra(KEY_SESSION_ID, sessionId); PendingIntent dismissalPendingIntent = PendingIntent.getService(this, (int) new Date().getTime(), dismissalIntent, PendingIntent.FLAG_UPDATE_CURRENT); String provideFeedbackTicker = res.getString(R.string.session_feedback_notification_ticker); NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this) .setColor(getResources().getColor(R.color.theme_primary)).setContentText(provideFeedbackTicker) .setTicker(provideFeedbackTicker) .setLights(SessionAlarmService.NOTIFICATION_ARGB_COLOR, SessionAlarmService.NOTIFICATION_LED_ON_MS, SessionAlarmService.NOTIFICATION_LED_OFF_MS) .setSmallIcon(R.drawable.ic_stat_notification).setPriority(Notification.PRIORITY_LOW) .setLocalOnly(true) // make it local to the phone .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE) .setDeleteIntent(dismissalPendingIntent).setAutoCancel(true); if (needFeedbackIds.size() == 1) { // Only 1 session needs feedback Uri sessionUri = ScheduleContract.Sessions.buildSessionUri(needFeedbackIds.get(0)); PendingIntent pi = TaskStackBuilder.create(this) .addNextIntent(new Intent(this, MyScheduleActivity.class)) .addNextIntent(new Intent(Intent.ACTION_VIEW, sessionUri, this, SessionFeedbackActivity.class)) .getPendingIntent(1, PendingIntent.FLAG_CANCEL_CURRENT); notifBuilder.setContentTitle(needFeedbackTitles.get(0)).setContentIntent(pi); } else { // Show information about several sessions that need feedback PendingIntent pi = TaskStackBuilder.create(this) .addNextIntent(new Intent(this, MyScheduleActivity.class)) .getPendingIntent(1, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); inboxStyle.setBigContentTitle(provideFeedbackTicker); for (String title : needFeedbackTitles) { inboxStyle.addLine(title); } notifBuilder .setContentTitle(getResources().getQuantityString(R.plurals.session_plurals, needFeedbackIds.size(), needFeedbackIds.size())) .setStyle(inboxStyle).setContentIntent(pi); } NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); LOGD(TAG, "Now showing session feedback notification!"); nm.notify(FEEDBACK_NOTIFICATION_ID, notifBuilder.build()); for (int i = 0; i < needFeedbackIds.size(); i++) { setupNotificationOnWear(needFeedbackIds.get(i), null, needFeedbackTitles.get(i), null); } }