List of usage examples for android.app Notification FLAG_NO_CLEAR
int FLAG_NO_CLEAR
To view the source code for android.app Notification FLAG_NO_CLEAR.
Click Source Link
From source file:com.sonetel.service.SipNotifications.java
public synchronized void notifyRegisteredAccounts(ArrayList<SipProfileState> activeAccountsInfos, boolean showNumbers) { if (!isServiceWrapper) { Log.e(THIS_FILE, "Trying to create a service notification from outside the service"); return;//from ww w . j av a2s.c o m } //int icon = R.drawable.ic_stat_sipok; int icon = R.drawable.sipok; CharSequence tickerText = context.getString(R.string.service_ticker_registered_text); long when = System.currentTimeMillis(); Builder nb = new NotificationCompat.Builder(context); nb.setSmallIcon(icon); nb.setTicker(tickerText); nb.setWhen(when); Intent notificationIntent = new Intent(SipManager.ACTION_SIP_DIALER); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); RegistrationNotification contentView = new RegistrationNotification(context.getPackageName()); contentView.clearRegistrations(); if (!Compatibility.isCompatible(9)) { contentView.setTextsColor(notificationPrimaryTextColor); } contentView.addAccountInfos(context, activeAccountsInfos); // notification.setLatestEventInfo(context, contentTitle, // contentText, contentIntent); nb.setOngoing(true); nb.setOnlyAlertOnce(true); nb.setContentIntent(contentIntent); nb.setContent(contentView); //Notification notification = nb.build(); Notification notification = nb.getNotification(); notification.flags |= Notification.FLAG_NO_CLEAR; // We have to re-write content view because getNotification setLatestEventInfo implicitly notification.contentView = contentView; if (showNumbers) { // This only affects android 2.3 and lower notification.number = activeAccountsInfos.size(); } startForegroundCompat(REGISTER_NOTIF_ID, notification); }
From source file:com.partypoker.poker.engagement.reach.EngagementDefaultNotifier.java
@Override public Boolean handleNotification(EngagementReachInteractiveContent content) throws RuntimeException { /* System notification case */ if (content.isSystemNotification()) { /* Big picture handling */ Bitmap bigPicture = null;//from w ww .j a v a 2s. c o m String bigPictureURL = content.getNotificationBigPicture(); if (bigPictureURL != null && Build.VERSION.SDK_INT >= 16) { /* Schedule picture download if needed, or load picture if download completed. */ Long downloadId = content.getDownloadId(); if (downloadId == null) { EngagementNotificationUtilsV11.downloadBigPicture(mContext, content); return null; } else bigPicture = EngagementNotificationUtilsV11.getBigPicture(mContext, downloadId); } /* Generate notification identifier */ int notificationId = getNotificationId(content); /* Build notification using support lib to manage compatibility with old Android versions */ NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext); /* Icon for ticker and content icon */ builder.setSmallIcon(mNotificationIcon); /* * Large icon, handled only since API Level 11 (needs down scaling if too large because it's * cropped otherwise by the system). */ Bitmap notificationImage = content.getNotificationImage(); if (notificationImage != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) builder.setLargeIcon(scaleBitmapForLargeIcon(mContext, notificationImage)); /* Texts */ String notificationTitle = content.getNotificationTitle(); String notificationMessage = content.getNotificationMessage(); String notificationBigText = content.getNotificationBigText(); builder.setContentTitle(notificationTitle); builder.setContentText(notificationMessage); /* * Replay: display original date and don't replay all the tickers (be as quiet as possible * when replaying). */ Long notificationFirstDisplayedDate = content.getNotificationFirstDisplayedDate(); if (notificationFirstDisplayedDate != null) builder.setWhen(notificationFirstDisplayedDate); else builder.setTicker(notificationTitle); /* Big picture */ if (bigPicture != null) builder.setStyle(new BigPictureStyle().bigPicture(bigPicture).setBigContentTitle(notificationTitle) .setSummaryText(notificationMessage)); /* Big text */ else if (notificationBigText != null) builder.setStyle(new BigTextStyle().bigText(notificationBigText)); /* Vibration/sound if not a replay */ if (notificationFirstDisplayedDate == null) { int defaults = 0; if (content.isNotificationSound()) defaults |= Notification.DEFAULT_SOUND; if (content.isNotificationVibrate()) defaults |= Notification.DEFAULT_VIBRATE; builder.setDefaults(defaults); } /* Launch the receiver on action */ Intent actionIntent = new Intent(INTENT_ACTION_ACTION_NOTIFICATION); com.microsoft.azure.engagement.reach.EngagementReachAgent.setContentIdExtra(actionIntent, content); actionIntent.putExtra(INTENT_EXTRA_NOTIFICATION_ID, notificationId); Intent intent = content.getIntent(); if (intent != null) actionIntent.putExtra(INTENT_EXTRA_COMPONENT, intent.getComponent()); actionIntent.setPackage(mContext.getPackageName()); PendingIntent contentIntent = PendingIntent.getBroadcast(mContext, (int) content.getLocalId(), actionIntent, FLAG_CANCEL_CURRENT); builder.setContentIntent(contentIntent); /* Also launch receiver if the notification is exited (clear button) */ Intent exitIntent = new Intent(INTENT_ACTION_EXIT_NOTIFICATION); exitIntent.putExtra(INTENT_EXTRA_NOTIFICATION_ID, notificationId); EngagementReachAgent.setContentIdExtra(exitIntent, content); exitIntent.setPackage(mContext.getPackageName()); PendingIntent deleteIntent = PendingIntent.getBroadcast(mContext, (int) content.getLocalId(), exitIntent, FLAG_CANCEL_CURRENT); builder.setDeleteIntent(deleteIntent); /* Can be dismissed ? */ Notification notification = builder.build(); if (!content.isNotificationCloseable()) notification.flags |= Notification.FLAG_NO_CLEAR; /* Allow overriding */ if (onNotificationPrepared(notification, content)) /* * Submit notification, replacing the previous one if any (this should happen only if the * application process is restarted). */ mNotificationManager.notify(notificationId, notification); } /* Activity embedded notification case */ else { /* Get activity */ Activity activity = EngagementActivityManager.getInstance().getCurrentActivity().get(); /* Cannot notify in app if no activity provided */ if (activity == null) return false; /* Get notification area */ String category = content.getCategory(); int areaId = getInAppAreaId(category); View notificationAreaView = activity.findViewById(areaId); /* No notification area, check if we can install overlay */ if (notificationAreaView == null) { /* Check overlay is not disabled in this activity */ Bundle activityConfig = EngagementUtils.getActivityMetaData(activity); if (!activityConfig.getBoolean(METADATA_NOTIFICATION_OVERLAY, true)) return false; /* Inflate overlay layout and get reference to notification area */ View overlay = LayoutInflater.from(mContext).inflate(getOverlayLayoutId(category), null); activity.addContentView(overlay, new LayoutParams(MATCH_PARENT, MATCH_PARENT)); notificationAreaView = activity.findViewById(areaId); } /* Otherwise check if there is an overlay containing the area to restore visibility */ else { View overlay = activity.findViewById(getOverlayViewId(category)); if (overlay != null) overlay.setVisibility(View.VISIBLE); } /* Make the notification area visible */ notificationAreaView.setVisibility(View.VISIBLE); /* Prepare area */ prepareInAppArea(content, notificationAreaView); } /* Success */ return true; }
From source file:com.marianhello.cordova.bgloc.LocationUpdateService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { Log.i(TAG, "Received start id " + startId + ": " + intent); if (intent != null) { try { params = new JSONObject(intent.getStringExtra("params")); headers = new JSONObject(intent.getStringExtra("headers")); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace();//from w ww . j a v a2 s.c om } url = intent.getStringExtra("url"); stationaryRadius = Float.parseFloat(intent.getStringExtra("stationaryRadius")); distanceFilter = Integer.parseInt(intent.getStringExtra("distanceFilter")); scaledDistanceFilter = distanceFilter; desiredAccuracy = Integer.parseInt(intent.getStringExtra("desiredAccuracy")); locationTimeout = Integer.parseInt(intent.getStringExtra("locationTimeout")); isDebugging = Boolean.parseBoolean(intent.getStringExtra("isDebugging")); notificationTitle = intent.getStringExtra("notificationTitle"); notificationText = intent.getStringExtra("notificationText"); // Build a Notification required for running service in foreground. Intent main = new Intent(this, BackgroundGpsPlugin.class); main.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT); Notification.Builder builder = new Notification.Builder(this); builder.setContentTitle(notificationTitle); builder.setContentText(notificationText); builder.setSmallIcon(android.R.drawable.ic_menu_mylocation); builder.setContentIntent(pendingIntent); Notification notification; if (android.os.Build.VERSION.SDK_INT >= 16) { notification = buildForegroundNotification(builder); } else { notification = buildForegroundNotificationCompat(builder); } notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_FOREGROUND_SERVICE | Notification.FLAG_NO_CLEAR; startForeground(startId, notification); } Log.i(TAG, "- url: " + url); Log.i(TAG, "- params: " + params.toString()); Log.i(TAG, "- headers: " + headers.toString()); Log.i(TAG, "- stationaryRadius: " + stationaryRadius); Log.i(TAG, "- distanceFilter: " + distanceFilter); Log.i(TAG, "- desiredAccuracy: " + desiredAccuracy); Log.i(TAG, "- locationTimeout: " + locationTimeout); Log.i(TAG, "- isDebugging: " + isDebugging); Log.i(TAG, "- notificationTitle: " + notificationTitle); Log.i(TAG, "- notificationText: " + notificationText); this.setPace(false); //We want this service to continue running until it is explicitly stopped return START_REDELIVER_INTENT; }
From source file:com.morestudio.littledot.doctor.service.SipNotifications.java
public synchronized void notifyRegisteredAccounts(ArrayList<SipProfileState> activeAccountsInfos, boolean showNumbers) { if (!isServiceWrapper) { Log.e(THIS_FILE, "Trying to create a service notification from outside the service"); return;/*from w w w . j a v a 2 s .c o m*/ } int icon = R.drawable.ic_face_black_48dp; CharSequence tickerText = context.getString(R.string.service_ticker_registered_text); long when = System.currentTimeMillis(); Builder nb = new NotificationCompat.Builder(context); nb.setSmallIcon(icon); nb.setContentTitle("LittleDot Doctor"); nb.setContentText("Client Active"); nb.setTicker(tickerText); nb.setWhen(when); /**test kod**/ Intent intent = new Intent(context, ResultActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, (int) when, intent, 0); /**kraj test koda**/ /*Intent notificationIntent = new Intent(SipManager.ACTION_SIP_DIALER); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);*/ /*RegistrationNotification contentView = new RegistrationNotification(context.getPackageName()); contentView.clearRegistrations(); if(!Compatibility.isCompatible(9)) { contentView.setTextsColor(notificationPrimaryTextColor); } contentView.addAccountInfos(context, activeAccountsInfos);*/ // notification.setLatestEventInfo(context, contentTitle, // contentText, contentIntent); nb.setOngoing(true); nb.setOnlyAlertOnce(true); nb.setContentIntent(pendingIntent); //nb.setContent(contentView); Notification notification = nb.build(); notification.flags |= Notification.FLAG_NO_CLEAR; // We have to re-write content view because getNotification setLatestEventInfo implicitly //notification.contentView = contentView; if (showNumbers) { // This only affects android 2.3 and lower notification.number = activeAccountsInfos.size(); } startForegroundCompat(REGISTER_NOTIF_ID, notification); }
From source file:com.roamprocess1.roaming4world.service.SipNotifications.java
public synchronized void notifyRegisteredAccounts(ArrayList<SipProfileState> activeAccountsInfos, boolean showNumbers) { if (!isServiceWrapper) { Log.e(THIS_FILE, "Trying to create a service notification from outside the service"); System.out.println("SipNotifications class notifyRegisteredAccounts"); return;// w ww .j a v a 2s . c om } int icon = R.drawable.ic_stat_sipok; CharSequence tickerText = context.getString(R.string.service_ticker_registered_text); long when = System.currentTimeMillis(); System.out.println("SipNotification synchronized"); Builder nb = new NotificationCompat.Builder(context); nb.setSmallIcon(icon); nb.setTicker(tickerText); nb.setWhen(when); //Intent notificationIntent = new Intent(SipManager.ACTION_SIP_DIALER); Intent notificationIntent = new Intent("com.roamprocess1.roaming4world.R4wHome.R4w_ACTIVITY"); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); System.out.println("SipNitification synchronized 1"); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); System.out.println("SipNitification synchronized 2"); RegistrationNotification contentView = new RegistrationNotification(context.getPackageName()); contentView.clearRegistrations(); if (!Compatibility.isCompatible(9)) { contentView.setTextsColor(notificationPrimaryTextColor); } contentView.addAccountInfos(context, activeAccountsInfos); // notification.setLatestEventInfo(context, contentTitle, // contentText, contentIntent); nb.setOngoing(true); nb.setOnlyAlertOnce(true); nb.setContentIntent(contentIntent); nb.setContent(contentView); Notification notification = nb.build(); notification.flags |= Notification.FLAG_NO_CLEAR; // We have to re-write content view because getNotification setLatestEventInfo implicitly notification.contentView = contentView; if (showNumbers) { // This only affects android 2.3 and lower notification.number = activeAccountsInfos.size(); } startForegroundCompat(REGISTER_NOTIF_ID, notification); }
From source file:uk.org.openseizuredetector.SdServer.java
/** * Show a notification while this service is running. */// w ww.j a va 2s . c o m private void showNotification() { Log.v(TAG, "showNotification()"); CharSequence text = "OpenSeizureDetector Server Running"; Notification notification = new Notification(R.drawable.star_of_life_24x24, text, System.currentTimeMillis()); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0); notification.setLatestEventInfo(this, "OpenSeizureDetector Server", text, contentIntent); notification.flags |= Notification.FLAG_NO_CLEAR; mNM = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNM.notify(NOTIFICATION_ID, notification); }
From source file:com.ubergeek42.WeechatAndroid.service.RelayService.java
private void showNotification(String tickerText, String content) { PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, WeechatActivity.class), PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentIntent(contentIntent).setSmallIcon(R.drawable.ic_notification) .setContentTitle(getString(R.string.app_version)).setContentText(content).setTicker(tickerText) .setWhen(System.currentTimeMillis()); Notification notification = builder.getNotification(); notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR; notificationManger.notify(NOTIFICATION_ID, notification); }
From source file:com.mobiperf.MeasurementScheduler.java
/** * Create notification that indicates the service is running. *//*from w w w .j av a 2 s . c o m*/ private Notification createServiceRunningNotification() { // The intent to launch when the user clicks the expanded notification Intent intent = new Intent(this, SpeedometerApp.class); PendingIntent pendIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); // This constructor is deprecated in 3.x. But most phones still run 2.x systems Notification notice = new Notification(R.drawable.icon_statusbar, getString(R.string.notificationSchedulerStarted), System.currentTimeMillis()); notice.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; // This is deprecated in 3.x. But most phones still run 2.x systems notice.setLatestEventInfo(this, getString(R.string.app_name), getString(R.string.notificationServiceRunning), pendIntent); return notice; }
From source file:com.inloc.dr.StepService.java
/** * Show a notification while this service is running. */// w w w .ja v a 2s . com 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 pedometerIntent = new Intent(); pedometerIntent.setComponent(new ComponentName(this, DeadReckoning.class)); pedometerIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, pedometerIntent, 0); notification.setLatestEventInfo(this, text, getText(R.string.notification_subtitle), contentIntent); mNM.notify(R.string.app_name, notification); }
From source file:com.sonetel.service.SipNotifications.java
public synchronized void notifyNotRegisteredAccounts(ArrayList<SipProfileState> activeAccountsInfos, boolean showNumbers) { if (!isServiceWrapper) { Log.e(THIS_FILE, "Trying to create a service notification from outside the service"); return;/*from w w w .j av a 2 s . c o m*/ } //int icon = R.drawable.ic_stat_sipok; int icon = R.drawable.not_ok; CharSequence tickerText = context.getString(R.string.service_ticker_unregistered_text); long when = System.currentTimeMillis(); Builder nb = new NotificationCompat.Builder(context); nb.setSmallIcon(icon); nb.setTicker(tickerText); nb.setWhen(when); Intent notificationIntent = new Intent(SipManager.ACTION_SIP_DIALER); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); RegistrationNotification contentView = new RegistrationNotification(context.getPackageName()); contentView.clearRegistrations(); if (!Compatibility.isCompatible(9)) { contentView.setTextsColor(notificationPrimaryTextColor); } contentView.addInActiveAccountInfos(context, activeAccountsInfos); // notification.setLatestEventInfo(context, contentTitle, // contentText, contentIntent); nb.setOngoing(true); nb.setOnlyAlertOnce(true); nb.setContentIntent(contentIntent); nb.setContent(contentView); //Notification notification = nb.build(); Notification notification = nb.getNotification(); notification.flags |= Notification.FLAG_NO_CLEAR; // We have to re-write content view because getNotification setLatestEventInfo implicitly notification.contentView = contentView; if (showNumbers) { // This only affects android 2.3 and lower notification.number = activeAccountsInfos.size(); } startForegroundCompat(REGISTER_NOTIF_ID, notification); // if(account.pin == null || account.pin.equalsIgnoreCase("")) //{ //serviceHandler.sendMessage(serviceHandler.obtainMessage(TOAST_MESSAGE, 0, 0,"Unable to configure callthru. Please check your registration or contact Sonetel support")); Toast.makeText(context, "Unable to configure automated callthru. You may be need to enter your credentials", Toast.LENGTH_LONG).show(); }