List of usage examples for android.app Notification FLAG_INSISTENT
int FLAG_INSISTENT
To view the source code for android.app Notification FLAG_INSISTENT.
Click Source Link
From source file:com.adityarathi.muo.services.BuildMusicLibraryService.java
@Override public int onStartCommand(Intent intent, int startId, int flags) { //Create a persistent notification that keeps this service running and displays the scan progress. mBuilder = new NotificationCompat.Builder(mContext); mBuilder.setSmallIcon(R.mipmap.ic_launcher); mBuilder.setContentTitle(getResources().getString(R.string.building_music_library)); mBuilder.setTicker(getResources().getString(R.string.building_music_library)); mBuilder.setContentText(""); mBuilder.setProgress(0, 0, true);/* ww w . j av a 2s. c o m*/ mNotifyManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); mNotification = mBuilder.build(); mNotification.flags |= Notification.FLAG_INSISTENT | Notification.FLAG_NO_CLEAR; startForeground(mNotificationId, mNotification); //Go crazy with a full-on scan. AsyncBuildLibraryTask task = new AsyncBuildLibraryTask(mContext, this); task.setOnBuildLibraryProgressUpdate(WelcomeActivity.mBuildingLibraryProgressFragment); task.setOnBuildLibraryProgressUpdate(this); task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); return START_STICKY; }
From source file:com.aniruddhc.acemusic.player.Services.BuildMusicLibraryService.java
@Override public int onStartCommand(Intent intent, int startId, int flags) { //Create a persistent notification that keeps this service running and displays the scan progress. mBuilder = new NotificationCompat.Builder(mContext); mBuilder.setSmallIcon(R.drawable.notif_icon); mBuilder.setContentTitle(getResources().getString(R.string.building_music_library)); mBuilder.setTicker(getResources().getString(R.string.building_music_library)); mBuilder.setContentText(""); mBuilder.setProgress(0, 0, true);/* ww w.j a v a 2 s . c o m*/ mNotifyManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); mNotification = mBuilder.build(); mNotification.flags |= Notification.FLAG_INSISTENT | Notification.FLAG_NO_CLEAR; startForeground(mNotificationId, mNotification); //Go crazy with a full-on scan. AsyncBuildLibraryTask task = new AsyncBuildLibraryTask(mContext, this); task.setOnBuildLibraryProgressUpdate(WelcomeActivity.mBuildingLibraryProgressFragment); task.setOnBuildLibraryProgressUpdate(this); task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); return START_STICKY; }
From source file:com.adityarathi.muo.services.BuildMusicLibraryService.java
@Override public void onProgressUpdate(AsyncBuildLibraryTask task, String mCurrentTask, int overallProgress, int maxProgress, boolean mediaStoreTransferDone) { mBuilder = new NotificationCompat.Builder(mContext); mBuilder.setSmallIcon(R.mipmap.ic_launcher); mBuilder.setContentTitle(mCurrentTask); mBuilder.setTicker(mCurrentTask);/*from w w w . j a v a 2 s. c o m*/ mBuilder.setContentText(""); mBuilder.setProgress(maxProgress, overallProgress, false); mNotifyManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); mNotification = mBuilder.build(); mNotification.flags |= Notification.FLAG_INSISTENT | Notification.FLAG_NO_CLEAR; mNotifyManager.notify(mNotificationId, mNotification); }
From source file:com.aniruddhc.acemusic.player.Services.BuildMusicLibraryService.java
@Override public void onProgressUpdate(AsyncBuildLibraryTask task, String mCurrentTask, int overallProgress, int maxProgress, boolean mediaStoreTransferDone) { mBuilder = new NotificationCompat.Builder(mContext); mBuilder.setSmallIcon(R.drawable.notif_icon); mBuilder.setContentTitle(mCurrentTask); mBuilder.setTicker(mCurrentTask);// w w w . j av a2 s .co m mBuilder.setContentText(""); mBuilder.setProgress(maxProgress, overallProgress, false); mNotifyManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); mNotification = mBuilder.build(); mNotification.flags |= Notification.FLAG_INSISTENT | Notification.FLAG_NO_CLEAR; mNotifyManager.notify(mNotificationId, mNotification); }
From source file:it.technocontrolsystem.hypercontrol.gcm.HCGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. *//*from w w w .j a v a 2 s . c om*/ private void sendNotification(Bundle data) { String messagetype = data.getString("messagetype"); switch (messagetype) { // crea una notifica che quando cliccata apre il site in allarme case "alarm": String siteUUID = data.getString("sitenum"); Site site = DB.getSiteByUUID(siteUUID); if (site != null) { Intent intent = new Intent(); intent.setClass(this, SiteActivity.class); intent.putExtra("siteid", site.getId()); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT); String title = "Allarme"; title += " " + site.getName(); // String msg = ""; // try { // int plantnum = Integer.parseInt(data.getString("plantnum")); // Plant plant = DB.getPlantBySiteAndNumber(siteid, plantnum); // msg += plant.getName(); // // int areanum = Integer.parseInt(data.getString("areanum")); // Area area = DB.getAreaByIdPlantAndAreaNumber(plant.getId(), areanum); // msg += " " + area.getName(); // // } catch (Exception e) { // } String msg = data.getString("message"); Uri defaultSoundUri = Lib.resourceToUri(R.raw.siren); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher).setContentTitle(title).setContentText(msg) .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent); Notification mNotification = notificationBuilder.build(); mNotification.flags |= Notification.FLAG_INSISTENT; NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0, mNotification); } else { Log.e(TAG, "site uuid " + siteUUID + " not found"); } break; // crea una notifica informativa case "info": // qui creare la notifica // ... break; } // dopo la notifica sveglia il device PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wakeLock = pm.newWakeLock( (PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), getClass().getSimpleName()); wakeLock.acquire(); }
From source file:com.mattprecious.locnotifier.LocationService.java
private void approachingDestination() { Log.d(getClass().getSimpleName(), "Within distance to destination"); locationManager.removeUpdates(locationListener); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(), 0); String notifTitle = getString(R.string.notification_alert_title); String notifText = getString(R.string.notification_alert_text); runningNotification = null;/* ww w. j av a 2s . com*/ NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder.setSmallIcon(R.drawable.notification_alert).setContentTitle(notifTitle) .setContentText(notifText).setContentIntent(contentIntent).setAutoCancel(true); String tone = preferences.getString("tone", null); Uri toneUri = (tone == null) ? RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) : Uri.parse(tone); notificationBuilder.setSound(toneUri); if (preferences.getBoolean("vibrate", false)) { int shortVib = 150; int shortPause = 150; // vibrate 3 short times long[] pattern = { 0, shortVib, shortPause, shortVib, shortPause, shortVib, }; notificationBuilder.setVibrate(pattern); } notificationBuilder.setLights(0xffff0000, 500, 500); Notification notification = notificationBuilder.getNotification(); if (preferences.getBoolean("insistent", false)) { notification.flags |= Notification.FLAG_INSISTENT; } notificationManager.notify(0, notification); // send sms if (preferences.getBoolean("sms_enabled", false)) { String number = preferences.getString("sms_contact", null); String message = preferences.getString("sms_message", null); if (number != null && message != null) { SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage(number, null, message, null, null); } } stopSelf(); }
From source file:com.android.example.notificationshowcase.NotificationService.java
@Override protected void onHandleIntent(Intent intent) { ArrayList<Notification> mNotifications = new ArrayList<Notification>(); NotificationManager noMa = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); int bigtextId = mNotifications.size(); mNotifications.add(makeBigTextNotification(this, 0, bigtextId, System.currentTimeMillis())); int uploadId = mNotifications.size(); long uploadWhen = System.currentTimeMillis(); mNotifications.add(makeUploadNotification(this, 10, uploadWhen)); Notification phoneCall = new NotificationCompat.Builder(this).setContentTitle("Incoming call") .setContentText("Matias Duarte").setLargeIcon(getBitmap(this, R.drawable.matias_hed)) .setSmallIcon(R.drawable.stat_sys_phone_call).setDefaults(Notification.DEFAULT_SOUND) .setPriority(NotificationCompat.PRIORITY_MAX) .setContentIntent(ToastService.getPendingIntent(this, "Clicked on Matias")) .addAction(R.drawable.ic_dial_action_call, "Answer", ToastService.getPendingIntent(this, "call answered")) .addAction(R.drawable.ic_end_call, "Ignore", ToastService.getPendingIntent(this, "call ignored")) .setAutoCancel(true).build(); phoneCall.flags |= Notification.FLAG_INSISTENT; mNotifications.add(phoneCall);//from w w w. j av a 2 s. co m mNotifications.add( new NotificationCompat.Builder(this).setContentTitle("Stopwatch PRO").setContentText("Counting up") .setContentIntent(ToastService.getPendingIntent(this, "Clicked on Stopwatch")) .setSmallIcon(R.drawable.stat_notify_alarm).setUsesChronometer(true).build()); mNotifications.add( new NotificationCompat.Builder(this).setContentTitle("J Planning").setContentText("The Botcave") .setWhen(System.currentTimeMillis()).setSmallIcon(R.drawable.stat_notify_calendar) .setContentIntent(ToastService.getPendingIntent(this, "Clicked on calendar event")) .setContentInfo("7PM") .addAction(R.drawable.stat_notify_snooze, "+10 min", ToastService.getPendingIntent(this, "snoozed 10 min")) .addAction(R.drawable.stat_notify_snooze_longer, "+1 hour", ToastService.getPendingIntent(this, "snoozed 1 hr")) .addAction(R.drawable.stat_notify_email, "Email", makeEmailIntent(this, "gabec@example.com,mcleron@example.com,dsandler@example.com")) .build()); BitmapDrawable d = (BitmapDrawable) getResources().getDrawable(R.drawable.romainguy_rockaway); mNotifications.add(new NotificationCompat.BigPictureStyle(new NotificationCompat.Builder(this) .setContentTitle("Romain Guy") .setContentText("I was lucky to find a Canon 5D Mk III at a local Bay Area " + "store last week but I had not been able to try it in the field " + "until tonight. After a few days of rain the sky finally cleared " + "up. Rockaway Beach did not disappoint and I was finally able to " + "see what my new camera feels like when shooting landscapes.") .setSmallIcon(R.drawable.ic_stat_gplus) .setContentIntent(ToastService.getPendingIntent(this, "Clicked on bigPicture")) .setLargeIcon(getBitmap(this, R.drawable.romainguy_hed)) .addAction(R.drawable.add, "Add to Gallery", ToastService.getPendingIntent(this, "added! (just kidding)")) .setSubText("talk rocks!")).bigPicture(d.getBitmap()).build()); // Note: this may conflict with real email notifications StyleSpan bold = new StyleSpan(Typeface.BOLD); SpannableString line1 = new SpannableString("Alice: hey there!"); line1.setSpan(bold, 0, 5, 0); SpannableString line2 = new SpannableString("Bob: hi there!"); line2.setSpan(bold, 0, 3, 0); SpannableString line3 = new SpannableString("Charlie: Iz IN UR EMAILZ!!"); line3.setSpan(bold, 0, 7, 0); mNotifications.add(new NotificationCompat.InboxStyle( new NotificationCompat.Builder(this).setContentTitle("24 new messages") .setContentText("You have mail!").setSubText("test.hugo2@gmail.com") .setContentIntent(ToastService.getPendingIntent(this, "Clicked on Email")) .setSmallIcon(R.drawable.stat_notify_email)).setSummaryText("+21 more").addLine(line1) .addLine(line2).addLine(line3).build()); mNotifications .add(new NotificationCompat.Builder(this).setContentTitle("Twitter").setContentText("New mentions") .setContentIntent(ToastService.getPendingIntent(this, "Clicked on Twitter")) .setSmallIcon(R.drawable.twitter_icon).setNumber(15) .setPriority(NotificationCompat.PRIORITY_LOW).build()); for (int i = 0; i < mNotifications.size(); i++) { noMa.notify(NOTIFICATION_ID + i, mNotifications.get(i)); } ProgressService.startProgressUpdater(this, uploadId, uploadWhen, 0); }
From source file:com.apps.howard.vicissitude.services.NotificationService.java
private void buildNotification(String message, String sender) { String newNotificationMessage = maybeSetNotificationMessage(sender); newNotificationMessage += message + System.getProperty("line.separator"); NotificationCompat.Builder mBuilder = getNotificationBuilder(message, sender); // Creates an explicit intent for an Activity in your app Notification mNotification;/*from ww w .java2s. c om*/ Intent resultIntent = new Intent(this, NotificationService.class); resultIntent.setAction(sender); PendingIntent resultPendingIntent = PendingIntent.getService(this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); mBuilder.setDeleteIntent(resultPendingIntent); mNotification = mBuilder.build(); mNotification.flags |= Notification.FLAG_INSISTENT; this.lastNotificationMessage.put(sender, newNotificationMessage); maybeOverrideVolumeBeforeNotify(); notificationManager.notify(sender, 1, mNotification); vibrator.vibrate(vibrationPattern, 0); }
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();/*from ww w . java2 s . co 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:es.usc.citius.servando.calendula.activities.ReminderNotification.java
private static Notification buildNotification(Context context, NotificationOptions options) { Resources res = context.getResources(); final NotificationCompat.Builder builder = new NotificationCompat.Builder(context) // Set appropriate defaults for the notification light, sound, and vibration. .setDefaults(Notification.DEFAULT_ALL) // Set required fields, including the small icon, the notification title, and text. .setSmallIcon(R.drawable.ic_pill_small).setContentTitle(options.title).setContentText(options.text) .setPriority(/*from w w w. j a v a2 s .c o m*/ options.insistent ? NotificationCompat.PRIORITY_MAX : NotificationCompat.PRIORITY_DEFAULT) // Provide a large icon, shown with the notification in the // notification drawer on devices running Android 3.0 or later. .setLargeIcon(options.picture) // Set ticker text (preview) information for this notification. .setTicker(options.ticker) // Show a number. This is useful when stacking notifications of a single type. .setNumber(options.notificationNumber).setWhen(options.when) // Set the pending intent to be initiated when the user touches the notification. .setContentIntent(options.defaultIntent) //.setOngoing(true) // add delay button .addAction(R.drawable.ic_history_white_24dp, res.getString(R.string.notification_delay), options.delayIntent) .addAction(R.drawable.ic_alarm_off_white_24dp, res.getString(R.string.notification_cancel_now), options.cancelIntent) // Show an expanded list of items on devices running Android 4.1 // or later. .setStyle(options.style) //.setLights(0x00ff0000, 500, 1000) .setPriority(Notification.PRIORITY_DEFAULT) .setVibrate(new long[] { 1000, 200, 500, 200, 100, 200, 1000 }).setSound(options.ringtone) // Automatically dismiss the notification when it is touched. .setAutoCancel(true); if (options.insistent) { builder.setFullScreenIntent(options.defaultIntent, true); } Notification n = builder.build(); n.defaults = 0; n.ledARGB = 0x00ffa500; n.ledOnMS = 1000; n.ledOffMS = 2000; if (options.insistent) { n.flags |= Notification.FLAG_INSISTENT; } return n; }