List of usage examples for android.app Notification FLAG_ONGOING_EVENT
int FLAG_ONGOING_EVENT
To view the source code for android.app Notification FLAG_ONGOING_EVENT.
Click Source Link
From source file:com.ubergeek42.WeechatAndroid.service.RelayServiceBackbone.java
/** build notification without displaying it * * @param tickerText text that flashes a bit, can be null * @param content text that appears under title * @param intent intent that's executed on notification click, can be null * @return built notification *//*from w w w. ja va 2 s . c om*/ @TargetApi(16) private Notification buildNotification(@Nullable String tickerText, @NonNull String content, @Nullable PendingIntent intent) { if (DEBUG_NOTIFICATIONS) logger.debug("buildNotification({}, {}, {})", new Object[] { tickerText, content, intent }); PendingIntent contentIntent; contentIntent = (intent != null) ? intent : PendingIntent.getActivity(this, 0, new Intent(this, WeechatActivity.class), PendingIntent.FLAG_CANCEL_CURRENT); int icon; if (!isConnection(AUTHENTICATED)) { if (isConnection(CONNECTING)) icon = R.drawable.ic_connecting; else icon = R.drawable.ic_disconnected; } else if (hot_count == 0) icon = R.drawable.ic_connected; else icon = R.drawable.ic_hot; NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentIntent(contentIntent).setSmallIcon(icon) .setContentTitle("WeechatAndroid v" + BuildConfig.VERSION_NAME).setContentText(content) .setWhen(System.currentTimeMillis()); if (prefs.getBoolean(PREF_NOTIFICATION_TICKER, true)) { builder.setTicker(tickerText); } Notification notification = builder.build(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { notification.priority = Notification.PRIORITY_MIN; } notification.flags |= Notification.FLAG_ONGOING_EVENT; return notification; }
From source file:io.clh.lrt.androidservice.TraceListenerService.java
private void setNotification(String msg, boolean ongoing) { NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); int icon = R.drawable.ic_launcher; CharSequence notiText = msg;/*from w w w .j a v a2s . c o m*/ long meow = System.currentTimeMillis(); Notification notification = new Notification(icon, notiText, meow); Context context = getApplicationContext(); CharSequence contentTitle = "LRT notification"; CharSequence contentText = msg; Intent notificationIntent = new Intent(this, MainActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); int SERVER_DATA_RECEIVED = 1; if (ongoing) { notification.flags |= Notification.FLAG_ONGOING_EVENT; notification.flags |= Notification.FLAG_SHOW_LIGHTS; startForeground(1337, notification); } else { notificationManager.notify(SERVER_DATA_RECEIVED, notification); } }
From source file:org.unchiujar.umbra2.services.LocationService.java
private Notification createNotification() { String contentTitle = getString(R.string.app_name); String running = getString(R.string.running); CharSequence tickerText = contentTitle + " " + running; // instantiate notification Notification notification = new NotificationCompat.Builder(this).setTicker(tickerText) .setWhen(System.currentTimeMillis()).setSmallIcon(R.drawable.icon).build(); notification.flags |= Notification.FLAG_NO_CLEAR; notification.flags |= Notification.FLAG_ONGOING_EVENT; // Define the Notification's expanded message and Intent: CharSequence contentText = contentTitle + " " + running; Intent notificationIntent = new Intent(this, FogOfExplore.class); // notificationIntent.setAction("android.intent.action.VIEW"); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(this, contentTitle, contentText, contentIntent); return notification; }
From source file:com.siahmsoft.soundroid.sdk7.services.UploadService.java
/** * Show a notification while this service is running. */// w ww . j a v a 2 s.c o m private void showNotification(String text) { // Set the icon, scrolling text and timestamp Notification notification = new Notification(R.drawable.uploadtocloud, text, System.currentTimeMillis()); // The PendingIntent to launch our activity if the user selects this notification Intent i = new Intent(this, MeActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); /*Bundle bundle = new Bundle(); bundle.putInt("idTrack", soundcloudTrack.getmIdTrack()); i.putExtras(bundle);*/ PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT); // Set the info for the views that show in the notification panel. notification.setLatestEventInfo(this, "Uploading...", text, contentIntent); // We show this for as long as our service is processing a command. notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_AUTO_CANCEL; notification.number = totalUploads; // Send the notification. // We use a string id because it is a unique number. We use it later to cancel. mNM.notify(777, notification); }
From source file:edu.sage.spark.service.XmppConnectionAdapter.java
/** * Update the notification for the Beem status. * @param status the status to display./* w ww .ja v a 2s .c o m*/ * @param text the text to display. */ @SuppressWarnings("deprecation") private void updateNotification(int status, String text) { String mNotificationText = "Spark Status"; //almyz125 added this Notification mStatusNotification; mStatusNotification = new Notification(Status.getIconBarFromStatus(status), text, System.currentTimeMillis()); mStatusNotification.defaults = Notification.DEFAULT_LIGHTS; mStatusNotification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; mStatusNotification.setLatestEventInfo(mService, mNotificationText, text, //almyz125 added mNotificationText variable PendingIntent.getActivity(mService, 0, new Intent(mService, ChangeStatus.class), 0)); // bypass the preferences for notification mService.getNotificationManager().notify(BeemService.NOTIFICATION_STATUS_ID, mStatusNotification); }
From source file:com.beem.project.beem.service.XmppConnectionAdapter.java
/** * Update the notification for the Beem status. * @param status the status to display.// w w w.ja v a 2 s . com * @param text the text to display. */ private void updateNotification(int status, String text) { Notification mStatusNotification; mStatusNotification = new Notification(Status.getIconBarFromStatus(status), text, System.currentTimeMillis()); mStatusNotification.defaults = Notification.DEFAULT_LIGHTS; mStatusNotification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; mStatusNotification.setLatestEventInfo(mService, "Beem Status", text, PendingIntent.getActivity(mService, 0, new Intent(mService, ChangeStatus.class), 0)); // bypass the preferences for notification mService.getNotificationManager().notify(BeemService.NOTIFICATION_STATUS_ID, mStatusNotification); }
From source file:com.elixsr.portforwarder.forwarding.ForwardingService.java
/** * Construct a notification//from w w w . ja va2 s .co m */ private void showForwardingEnabledNotification() { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_fwd_24dp).setContentTitle("Port Forwarding Active") .setContentText("Touch to disable"); mBuilder.setColor(ContextCompat.getColor(this, R.color.colorPrimaryDark)); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(this, MainActivity.class); // The stack builder object will contain an artificial back stack for the // started Activity. // This ensures that navigating backward from the Activity leads out of // your application to the Home screen. TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(MainActivity.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); Notification notification = mBuilder.build(); notification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT | Notification.DEFAULT_LIGHTS; // mId allows you to update the notification later on. mNotificationManager.notify(NOTIFICATION_ID, notification); }
From source file:name.setup.dance.StepService.java
/** * Show a notification while this service is running. *///from w w w. ja va2 s.c o m private void showNotification() { CharSequence text = getText(R.string.app_name); Notification notification = new Notification(R.drawable.ic_notification, null, System.currentTimeMillis()); notification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; Intent DanceStepAppIntent = new Intent(); DanceStepAppIntent.setComponent(new ComponentName(this, DanceStepApp.class)); DanceStepAppIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, DanceStepAppIntent, 0); notification.setLatestEventInfo(this, text, getText(R.string.notification_subtitle), contentIntent); mNM.notify(R.string.app_name, notification); }
From source file:com.fanfou.app.opensource.service.DownloadService.java
private void showProgress() { this.notification = new Notification(R.drawable.ic_notify_download, "?", System.currentTimeMillis()); this.notification.flags |= Notification.FLAG_ONGOING_EVENT; this.notification.flags |= Notification.FLAG_AUTO_CANCEL; this.notification.contentIntent = PendingIntent.getActivity(this, 0, new Intent(), 0); final RemoteViews view = new RemoteViews(getPackageName(), R.layout.download_notification); view.setTextViewText(R.id.download_notification_text, "? 0%"); view.setProgressBar(R.id.download_notification_progress, 100, 0, false); this.notification.contentView = view; this.nm.notify(DownloadService.NOTIFICATION_PROGRESS_ID, this.notification); }
From source file:edu.missouri.bas.service.SensorService.java
@SuppressWarnings("deprecation") @Override//from w w w .j a v a2 s . com public void onCreate() { super.onCreate(); Log.d(TAG, "Starting sensor service"); mSoundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 100); soundsMap = new HashMap<Integer, Integer>(); soundsMap.put(SOUND1, mSoundPool.load(this, R.raw.bodysensor_alarm, 1)); soundsMap.put(SOUND2, mSoundPool.load(this, R.raw.voice_notification, 1)); serviceContext = this; mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); bluetoothMacAddress = mBluetoothAdapter.getAddress(); mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); //Get location manager mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); activityRecognition = new ActivityRecognitionScan(getApplicationContext()); activityRecognition.startActivityRecognitionScan(); mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); serviceWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "SensorServiceLock"); serviceWakeLock.acquire(); //Initialize start time stime = System.currentTimeMillis(); //Setup calendar object Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(stime); /* * Setup notification manager */ notification = new Notification(R.drawable.icon2, "Recorded", System.currentTimeMillis()); notification.defaults = 0; notification.flags |= Notification.FLAG_ONGOING_EVENT; notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Intent notifyIntent = new Intent(Intent.ACTION_MAIN); notifyIntent.setClass(this, MainActivity.class); /* * Display notification that service has started */ notification.tickerText = "Sensor Service Running"; PendingIntent contentIntent = PendingIntent.getActivity(SensorService.this, 0, notifyIntent, Notification.FLAG_ONGOING_EVENT); notification.setLatestEventInfo(SensorService.this, getString(R.string.app_name), "Recording service started at: " + cal.getTime().toString(), contentIntent); notificationManager.notify(SensorService.SERVICE_NOTIFICATION_ID, notification); // locationControl = new LocationControl(this, mLocationManager, 1000 * 60, 200, 5000); IntentFilter activityResultFilter = new IntentFilter(XMLSurveyActivity.INTENT_ACTION_SURVEY_RESULTS); SensorService.this.registerReceiver(alarmReceiver, activityResultFilter); IntentFilter sensorDataFilter = new IntentFilter(SensorService.ACTION_SENSOR_DATA); SensorService.this.registerReceiver(alarmReceiver, sensorDataFilter); Log.d(TAG, "Sensor service created."); try { prepareIO(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } prepareAlarms(); Intent startSensors = new Intent(SensorService.ACTION_START_SENSORS); this.sendBroadcast(startSensors); Intent scheduleCheckConnection = new Intent(SensorService.ACTION_SCHEDULE_CHECK); scheduleCheck = PendingIntent.getBroadcast(serviceContext, 0, scheduleCheckConnection, 0); mAlarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 1000 * 60 * 5, 1000 * 60 * 5, scheduleCheck); mLocationClient = new LocationClient(this, this, this); }