List of usage examples for android.app Notification PRIORITY_MIN
int PRIORITY_MIN
To view the source code for android.app Notification PRIORITY_MIN.
Click Source Link
From source file:com.daiv.android.twitter.services.TestPullNotificationService.java
@Override public void onCreate() { super.onCreate(); if (TestPullNotificationService.isRunning) { stopSelf();//from www. j a va 2 s .c o m return; } TestPullNotificationService.isRunning = true; settings = AppSettings.getInstance(this); mCache = App.getInstance(this).getBitmapCache(); sharedPreferences = getSharedPreferences("com.daiv.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); showNotification = sharedPreferences.getBoolean("show_pull_notification", true); pullUnread = sharedPreferences.getInt("pull_unread", 0); Intent notificationIntent = new Intent(this, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); Intent stop = new Intent(this, StopPull.class); PendingIntent stopPending = PendingIntent.getService(this, 0, stop, 0); String text; int count = 0; if (sharedPreferences.getBoolean("is_logged_in_1", false)) { count++; } if (sharedPreferences.getBoolean("is_logged_in_2", false)) { count++; } boolean multAcc = false; if (count == 2) { multAcc = true; } if (settings.liveStreaming && settings.timelineNot) { text = getResources().getString(R.string.new_tweets_upper) + ": " + pullUnread; } else { text = getResources().getString(R.string.listening_for_mentions) + "..."; } mBuilder = new NotificationCompat.Builder(this).setSmallIcon(android.R.color.transparent) .setContentTitle(getResources().getString(R.string.Test_pull) + (multAcc ? " - @" + settings.myScreenName : "")) .setContentText(text).setOngoing(true) .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.ic_stat_icon)); if (getApplicationContext().getResources().getBoolean(R.bool.expNotifications)) { mBuilder.addAction(R.drawable.ic_cancel_dark, getApplicationContext().getResources().getString(R.string.stop), stopPending); } try { mBuilder.setWhen(0); } catch (Exception e) { } mBuilder.setContentIntent(pendingIntent); // priority flag is only available on api level 16 and above if (getResources().getBoolean(R.bool.expNotifications)) { mBuilder.setPriority(Notification.PRIORITY_MIN); } mContext = getApplicationContext(); IntentFilter filter = new IntentFilter(); filter.addAction("com.daiv.android.twitter.STOP_PUSH"); registerReceiver(stopPush, filter); filter = new IntentFilter(); filter.addAction("com.daiv.android.twitter.START_PUSH"); registerReceiver(startPush, filter); filter = new IntentFilter(); filter.addAction("com.daiv.android.twitter.STOP_PUSH_SERVICE"); registerReceiver(stopService, filter); if (settings.liveStreaming && settings.timelineNot) { filter = new IntentFilter(); filter.addAction("com.daiv.android.twitter.UPDATE_NOTIF"); registerReceiver(updateNotification, filter); filter = new IntentFilter(); filter.addAction("com.daiv.android.twitter.NEW_TWEET"); registerReceiver(updateNotification, filter); filter = new IntentFilter(); filter.addAction("com.daiv.android.twitter.CLEAR_PULL_UNREAD"); registerReceiver(clearPullUnread, filter); } Thread start = new Thread(new Runnable() { @Override public void run() { // get the ids of everyone you follow try { Log.v("getting_ids", "started getting ids, mine: " + settings.myId); Twitter twitter = Utils.getTwitter(mContext, settings); long currCursor = -1; IDs idObject; ids = new ArrayList<Long>(); do { idObject = twitter.getFriendsIDs(settings.myId, currCursor); long[] lIds = idObject.getIDs(); for (int i = 0; i < lIds.length; i++) { ids.add(lIds[i]); } } while ((currCursor = idObject.getNextCursor()) != 0); ids.add(settings.myId); currCursor = -1; blockedIds = new ArrayList<Long>(); do { idObject = twitter.getBlocksIDs(currCursor); long[] lIds = idObject.getIDs(); for (int i = 0; i < lIds.length; i++) { blockedIds.add(lIds[i]); } } while ((currCursor = idObject.getNextCursor()) != 0); idsLoaded = true; if (showNotification) startForeground(FOREGROUND_SERVICE_ID, mBuilder.build()); mContext.sendBroadcast(new Intent("com.daiv.android.twitter.START_PUSH")); } catch (Exception e) { e.printStackTrace(); TestPullNotificationService.isRunning = false; pullUnread = 0; Thread stop = new Thread(new Runnable() { @Override public void run() { TestPullNotificationService.shuttingDown = true; try { //pushStream.removeListener(userStream); } catch (Exception x) { } try { pushStream.cleanUp(); pushStream.shutdown(); Log.v("twitter_stream_push", "stopping push notifications"); } catch (Exception e) { // it isn't running e.printStackTrace(); // try twice to shut it down i guess try { Thread.sleep(2000); pushStream.cleanUp(); pushStream.shutdown(); Log.v("twitter_stream_push", "stopping push notifications"); } catch (Exception x) { // it isn't running x.printStackTrace(); } } TestPullNotificationService.shuttingDown = false; } }); stop.setPriority(Thread.MAX_PRIORITY); stop.start(); stopSelf(); } catch (OutOfMemoryError e) { TestPullNotificationService.isRunning = false; Thread stop = new Thread(new Runnable() { @Override public void run() { TestPullNotificationService.shuttingDown = true; try { //pushStream.removeListener(userStream); } catch (Exception x) { } try { pushStream.cleanUp(); pushStream.shutdown(); Log.v("twitter_stream_push", "stopping push notifications"); } catch (Exception e) { // it isn't running e.printStackTrace(); // try twice to shut it down i guess try { Thread.sleep(2000); pushStream.cleanUp(); pushStream.shutdown(); Log.v("twitter_stream_push", "stopping push notifications"); } catch (Exception x) { // it isn't running x.printStackTrace(); } } TestPullNotificationService.shuttingDown = false; } }); stop.setPriority(Thread.MAX_PRIORITY); stop.start(); pullUnread = 0; stopSelf(); } } }); start.setPriority(Thread.MAX_PRIORITY - 1); start.start(); }
From source file:cz.msebera.unbound.dns.UnboundService.java
private void goForeground() { if (mIsForeground) { return;//from w w w . j av a 2 s .c om } Intent stopIntent = new Intent(getApplicationContext(), UnboundService.class); stopIntent.setAction(ACTION_STOP); PendingIntent stopPendingIntent = PendingIntent.getService(getApplicationContext(), REQUEST_STOP, stopIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Action stopAction = new NotificationCompat.Action.Builder( android.R.drawable.ic_media_pause, getString(R.string.menu_stop), stopPendingIntent).build(); Notification notification = new NotificationCompat.Builder(getApplicationContext()) .setContentTitle(getString(R.string.app_name)).setSmallIcon(R.mipmap.ic_launcher) .setPriority(Notification.PRIORITY_MIN).setCategory(NotificationCompat.CATEGORY_SERVICE) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC).setColor(Color.RED).addAction(stopAction) .setWhen(System.currentTimeMillis()).setVisibility(NotificationCompat.VISIBILITY_PRIVATE) .setOngoing(true).build(); startForeground(NOTIFICATION_ID, notification); mIsForeground = true; }
From source file:com.klinker.android.twitter.services.TalonPullNotificationService.java
@Override public void onCreate() { super.onCreate(); if (TalonPullNotificationService.isRunning) { stopSelf();/*from w w w .j ava2 s . co m*/ return; } TalonPullNotificationService.isRunning = true; settings = AppSettings.getInstance(this); mCache = App.getInstance(this).getBitmapCache(); sharedPreferences = getSharedPreferences("com.klinker.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); pullUnread = sharedPreferences.getInt("pull_unread", 0); Intent notificationIntent = new Intent(this, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); Intent stop = new Intent(this, StopPull.class); PendingIntent stopPending = PendingIntent.getService(this, 0, stop, 0); Intent popup = new Intent(this, RedirectToPopup.class); popup.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); popup.putExtra("from_notification", true); PendingIntent popupPending = PendingIntent.getActivity(this, 0, popup, 0); Intent compose = new Intent(this, WidgetCompose.class); popup.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent composePending = PendingIntent.getActivity(this, 0, compose, 0); String text; int count = 0; if (sharedPreferences.getBoolean("is_logged_in_1", false)) { count++; } if (sharedPreferences.getBoolean("is_logged_in_2", false)) { count++; } boolean multAcc = false; if (count == 2) { multAcc = true; } if (settings.liveStreaming && settings.timelineNot) { text = getResources().getString(R.string.new_tweets_upper) + ": " + pullUnread; } else { text = getResources().getString(R.string.listening_for_mentions) + "..."; } mBuilder = new NotificationCompat.Builder(this).setSmallIcon(android.R.color.transparent) .setContentTitle(getResources().getString(R.string.talon_pull) + (multAcc ? " - @" + settings.myScreenName : "")) .setContentText(text).setOngoing(true) .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.ic_stat_icon)); if (getApplicationContext().getResources().getBoolean(R.bool.expNotifications)) { mBuilder.addAction(R.drawable.ic_cancel_dark, getApplicationContext().getResources().getString(R.string.stop), stopPending); mBuilder.addAction(R.drawable.ic_popup, getResources().getString(R.string.popup), popupPending); mBuilder.addAction(R.drawable.ic_send_dark, getResources().getString(R.string.tweet), composePending); } try { mBuilder.setWhen(0); } catch (Exception e) { } mBuilder.setContentIntent(pendingIntent); // priority flag is only available on api level 16 and above if (getResources().getBoolean(R.bool.expNotifications)) { mBuilder.setPriority(Notification.PRIORITY_MIN); } mContext = getApplicationContext(); IntentFilter filter = new IntentFilter(); filter.addAction("com.klinker.android.twitter.STOP_PUSH"); registerReceiver(stopPush, filter); filter = new IntentFilter(); filter.addAction("com.klinker.android.twitter.START_PUSH"); registerReceiver(startPush, filter); filter = new IntentFilter(); filter.addAction("com.klinker.android.twitter.STOP_PUSH_SERVICE"); registerReceiver(stopService, filter); if (settings.liveStreaming && settings.timelineNot) { filter = new IntentFilter(); filter.addAction("com.klinker.android.twitter.UPDATE_NOTIF"); registerReceiver(updateNotification, filter); filter = new IntentFilter(); filter.addAction("com.klinker.android.twitter.NEW_TWEET"); registerReceiver(updateNotification, filter); filter = new IntentFilter(); filter.addAction("com.klinker.android.twitter.CLEAR_PULL_UNREAD"); registerReceiver(clearPullUnread, filter); } Thread start = new Thread(new Runnable() { @Override public void run() { // get the ids of everyone you follow try { Log.v("getting_ids", "started getting ids, mine: " + settings.myId); Twitter twitter = Utils.getTwitter(mContext, settings); long currCursor = -1; IDs idObject; int rep = 0; do { idObject = twitter.getFriendsIDs(settings.myId, currCursor); long[] lIds = idObject.getIDs(); ids = new ArrayList<Long>(); for (int i = 0; i < lIds.length; i++) { ids.add(lIds[i]); } rep++; } while ((currCursor = idObject.getNextCursor()) != 0 && rep < 3); ids.add(settings.myId); idsLoaded = true; startForeground(FOREGROUND_SERVICE_ID, mBuilder.build()); mContext.sendBroadcast(new Intent("com.klinker.android.twitter.START_PUSH")); } catch (Exception e) { e.printStackTrace(); TalonPullNotificationService.isRunning = false; pullUnread = 0; Thread stop = new Thread(new Runnable() { @Override public void run() { TalonPullNotificationService.shuttingDown = true; try { //pushStream.removeListener(userStream); } catch (Exception x) { } try { pushStream.cleanUp(); pushStream.shutdown(); Log.v("twitter_stream_push", "stopping push notifications"); } catch (Exception e) { // it isn't running e.printStackTrace(); // try twice to shut it down i guess try { Thread.sleep(2000); pushStream.cleanUp(); pushStream.shutdown(); Log.v("twitter_stream_push", "stopping push notifications"); } catch (Exception x) { // it isn't running x.printStackTrace(); } } TalonPullNotificationService.shuttingDown = false; } }); stop.setPriority(Thread.MAX_PRIORITY); stop.start(); stopSelf(); } catch (OutOfMemoryError e) { TalonPullNotificationService.isRunning = false; Thread stop = new Thread(new Runnable() { @Override public void run() { TalonPullNotificationService.shuttingDown = true; try { //pushStream.removeListener(userStream); } catch (Exception x) { } try { pushStream.cleanUp(); pushStream.shutdown(); Log.v("twitter_stream_push", "stopping push notifications"); } catch (Exception e) { // it isn't running e.printStackTrace(); // try twice to shut it down i guess try { Thread.sleep(2000); pushStream.cleanUp(); pushStream.shutdown(); Log.v("twitter_stream_push", "stopping push notifications"); } catch (Exception x) { // it isn't running x.printStackTrace(); } } TalonPullNotificationService.shuttingDown = false; } }); stop.setPriority(Thread.MAX_PRIORITY); stop.start(); pullUnread = 0; stopSelf(); } } }); start.setPriority(Thread.MAX_PRIORITY - 1); start.start(); }
From source file:com.cyanogenmod.settings.otgtoggle.UsbDeviceMonitorService.java
void updateNotification(boolean connected, int mode) { NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); if (!connected) { nm.cancel(OTG_NOTIFICATION_ID);/*w w w. j ava2s . c o m*/ return; } final Intent clickIntent = new Intent(this, OtgModeChooserActivity.class) .putExtra(OtgModeChooserActivity.EXTRA_CURRENT_MODE, getDetectionMode()); final PendingIntent clickPi = PendingIntent.getActivity(this, 0, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT); final int titleResId; switch (mode) { case MODE_HEADSET: titleResId = R.string.connection_notification_title_headset; break; case MODE_OTG: titleResId = R.string.connection_notification_title_otg; break; default: titleResId = R.string.connection_notification_title_detect; break; } final Notification.Builder builder = new Notification.Builder(this) .setSmallIcon(R.drawable.ic_headset_notification).setLocalOnly(true).setOngoing(true).setWhen(0) .setDefaults(0).setShowWhen(false).setCategory(Notification.CATEGORY_SERVICE) .setVisibility(Notification.VISIBILITY_PUBLIC).setPriority(Notification.PRIORITY_MIN) .setColor(getResources().getColor(com.android.internal.R.color.system_notification_accent_color)) .setContentTitle(getString(titleResId)) .setContentText(getString(R.string.connection_notification_text)).setContentIntent(clickPi); nm.notify(OTG_NOTIFICATION_ID, builder.build()); }
From source file:com.mattprecious.locnotifier.LocationService.java
@TargetApi(16) private void updateRunningNotification(float distance) { String message;//from ww w .ja va 2s .com if (distance == -1) { message = getString(R.string.notification_awaiting); } else { boolean imperial = preferences.getBoolean("imperial", false); int distanceStrId = imperial ? R.string.distance_feet : R.string.distance_metres; long displayDistance = imperial ? Math.round(distance * 3.2808399) : Math.round(distance); message = getString(R.string.notification_tracking, getString(distanceStrId, displayDistance)); } String title = getString(R.string.app_name); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, LocationNotifier.class), 0); if (runningNotification == null) { runningNotification = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.notification_running) .setContentTitle(title).setContentText(message).setContentIntent(contentIntent) .setOnlyAlertOnce(true).getNotification(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { if (preferences.getString("notification_priority", "low").equals("low")) { runningNotification.priority = Notification.PRIORITY_MIN; } else { runningNotification.priority = Notification.PRIORITY_HIGH; } } startForeground(R.string.app_name, runningNotification); } else { // TODO: Figure out how to do this without using the deprecated setLatestEventInfo runningNotification.setLatestEventInfo(this, title, message, contentIntent); notificationManager.notify(R.string.app_name, runningNotification); } }
From source file:com.farmerbb.secondscreen.service.NotificationService.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override/* ww w.j a va2 s .c o m*/ public void onCreate() { // Load preferences SharedPreferences prefCurrent = U.getPrefCurrent(this); SharedPreferences prefMain = U.getPrefMain(this); // Register broadcast receivers for screen on and user present final IntentFilter filter1 = new IntentFilter(); final IntentFilter filter2 = new IntentFilter(); filter1.addAction(Intent.ACTION_SCREEN_ON); filter1.addAction(Intent.ACTION_DREAMING_STARTED); filter2.addAction(Intent.ACTION_USER_PRESENT); registerReceiver(screenOnReceiver, filter1); registerReceiver(userPresentReceiver, filter2); DisplayManager manager = (DisplayManager) getSystemService(DISPLAY_SERVICE); manager.registerDisplayListener(listener, null); // Intent to launch MainActivity when notification is clicked Intent mainActivityIntent = new Intent(this, MainActivity.class); PendingIntent mainActivityPendingIntent = PendingIntent.getActivity(this, 0, mainActivityIntent, PendingIntent.FLAG_UPDATE_CURRENT); // Build the notification mBuilder = new NotificationCompat.Builder(this).setContentIntent(mainActivityPendingIntent) .setSmallIcon(R.drawable.ic_action_dock) .setContentTitle(getResources().getString(R.string.notification)) .setContentText( prefCurrent.getString("profile_name", getResources().getString(R.string.action_new))) .setOngoing(true); // Set action buttons setActionButton(prefMain.getString("notification_action_2", "turn-off"), prefCurrent, 0); setActionButton(prefMain.getString("notification_action", "lock-device"), prefCurrent, 1); // Respect setting to hide notification if (prefMain.getBoolean("hide_notification", false)) mBuilder.setPriority(Notification.PRIORITY_MIN); // Set notification color on Lollipop if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mBuilder.setColor(getResources().getColor(R.color.primary_dark)) .setVisibility(Notification.VISIBILITY_PUBLIC); } // Start NotificationService startForeground(1, mBuilder.build()); // Draw system overlay, if needed if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && Settings.canDrawOverlays(this) && prefCurrent.getString("rotation_lock_new", "fallback").equals("landscape")) { windowManager = (WindowManager) getSystemService(WINDOW_SERVICE); WindowManager.LayoutParams params = new WindowManager.LayoutParams( WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT); params.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; view = new View(this); windowManager.addView(view, params); } }
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<>(); {/*from w ww.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:com.securecomcode.text.service.KeyCachingService.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void foregroundServiceModern() { NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentTitle(getString(R.string.KeyCachingService_passphrase_cached)); builder.setContentText(getString(R.string.KeyCachingService_textsecure_passphrase_cached)); builder.setSmallIcon(R.drawable.icon_cached); builder.setWhen(0);/*from www. j a v a 2 s. co m*/ builder.setPriority(Notification.PRIORITY_MIN); builder.addAction(R.drawable.ic_menu_lock_holo_dark, getString(R.string.KeyCachingService_lock), buildLockIntent()); builder.setContentIntent(buildLaunchIntent()); stopForeground(true); startForeground(SERVICE_RUNNING_ID, builder.build()); }
From source file:com.linkbubble.MainService.java
private void showDefaultNotification() { Intent closeAllIntent = new Intent(this, NotificationCloseAllActivity.class); closeAllIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent closeAllPendingIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), closeAllIntent, PendingIntent.FLAG_UPDATE_CURRENT); /*Intent showContentViewIntent = new Intent(this, NotificationShowContentActivity.class); showContentViewIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent showContentViewPendingIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), showContentViewIntent, PendingIntent.FLAG_UPDATE_CURRENT);*/ Intent hideIntent = new Intent(this, NotificationHideActivity.class); hideIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent hidePendingIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), hideIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat).setPriority(Notification.PRIORITY_MIN) .setContentTitle(getString(R.string.app_name)) .setContentText(getString(R.string.notification_default_summary)) //.addAction(R.drawable.ic_action_eye_closed_dark, getString(R.string.notification_action_hide), hidePendingIntent) //.addAction(R.drawable.ic_action_cancel_dark, getString(R.string.notification_action_close_all), closeAllPendingIntent) .addAction(//w ww . j a v a 2s. com Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT ? R.drawable.ic_action_cancel_white : R.drawable.ic_action_cancel_dark, getString(R.string.notification_action_close_all), closeAllPendingIntent) //.addAction(Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT ? R.drawable.ic_action_cancel_white : R.drawable.ic_action_cancel_dark, getString(R.string.notification_expand), showContentViewPendingIntent) .setGroup(Constant.NOTIFICATION_GROUP_KEY_ARTICLES).setGroupSummary(true).setLocalOnly(true) .setContentIntent(hidePendingIntent); /*MainController controller = MainController.get(); if (null != controller && null != controller.mBubbleFlowDraggable) { if (!controller.mBubbleFlowDraggable.isExpanded()) { notificationBuilder .addAction(R.drawable.ic_stat, getString(R.string.notification_expand), showContentViewPendingIntent) .setContentText(getString(R.string.notification_default_expand_summary)); } }*/ // Nuke all previous notifications and generate unique ids NotificationManagerCompat.from(this).cancelAll(); int notificationId = 77; startForeground(notificationId, notificationBuilder.build()); }
From source file:com.achep.acdisplay.services.BathService.java
/** * <p>NOT SYNCHRONIZED!</p>/*from w w w .j a va2 s. c o m*/ * Builds fresh notification with all {@link ChildService children services}'s * {@link com.achep.acdisplay.services.BathService.ChildService#getLabel() labels} in. * Content intent starts {@link com.achep.acdisplay.activities.MainActivity}. */ private Notification buildNotification() { boolean empty = true; StringBuilder builder = new StringBuilder(); String divider = getString(R.string.settings_multi_list_divider); for (ChildService child : mMap.values()) { if (!empty) { builder.append(divider); } builder.append(child.getLabel()); empty = false; } String contentText = builder.toString(); if (contentText.length() > 0) { contentText = contentText.charAt(0) + contentText.substring(1).toLowerCase(); } PendingIntent pendingIntent = PendingIntent.getActivity(this, App.ID_NOTIFY_BATH, new Intent(this, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT); return new Notification.Builder(this).setContentTitle(getString(R.string.service_bath)) .setContentText(contentText).setContentIntent(pendingIntent).setSmallIcon(R.drawable.stat_acdisplay) .setPriority(Notification.PRIORITY_MIN).build(); }