List of usage examples for android.app PendingIntent FLAG_UPDATE_CURRENT
int FLAG_UPDATE_CURRENT
To view the source code for android.app PendingIntent FLAG_UPDATE_CURRENT.
Click Source Link
From source file:com.nextgis.firereporter.GetFiresService.java
protected void ScheduleNextUpdate(Context context, int nCommand, long nMinTimeBetweenSend, boolean bEnergyEconomy) { if (context == null) return;//from w w w. j a v a2 s .co m Intent intent = new Intent(MainActivity.INTENT_NAME); intent.putExtra(RECEIVER, mUserNasaReceiver); intent.putExtra(RECEIVER_SCANEX, mScanexReceiver); intent.putExtra(COMMAND, nCommand); intent.putExtra(SOURCE, mnFilter); PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); // The update frequency should often be user configurable. This is not. long currentTimeMillis = System.currentTimeMillis(); long nextUpdateTimeMillis = currentTimeMillis + nMinTimeBetweenSend; Time nextUpdateTime = new Time(); nextUpdateTime.set(nextUpdateTimeMillis); AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); if (bEnergyEconomy) alarmManager.set(AlarmManager.RTC, nextUpdateTimeMillis, pendingIntent); else alarmManager.set(AlarmManager.RTC_WAKEUP, nextUpdateTimeMillis, pendingIntent); }
From source file:com.aengbee.android.leanback.ui.PlaybackOverlayCustomFragment.java
private boolean updateSelectedVideo(Video video) { Intent intent = new Intent(getActivity().getIntent()); intent.putExtra(VideoDetailsActivity.VIDEO, video); if (mSelectedVideo != null && mSelectedVideo.equals(video)) { return false; }/*from ww w. j a va2 s. c o m*/ mSelectedVideo = video; PendingIntent pi = PendingIntent.getActivity(getActivity(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); mSession.setSessionActivity(pi); return true; }
From source file:com.openerp.base.ir.Attachment.java
@SuppressWarnings("deprecation") private Notification setFileIntent(Uri uri) { Log.v(TAG, "setFileIntent()"); Intent intent = new Intent(Intent.ACTION_VIEW); FileNameMap mime = URLConnection.getFileNameMap(); String mimeType = mime.getContentTypeFor(uri.getPath()); intent.setDataAndType(uri, mimeType); mNotificationResultIntent = PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); mNotificationBuilder.addAction(R.drawable.ic_oe_notification, "Download attachment", mNotificationResultIntent);/*from ww w . j a v a 2 s . c o m*/ mNotificationBuilder.setOngoing(false); mNotificationBuilder.setAutoCancel(true); mNotificationBuilder.setContentTitle("Attachment downloaded"); mNotificationBuilder.setContentText("Download Complete"); mNotificationBuilder.setProgress(0, 0, false); mNotification = mNotificationBuilder.build(); mNotification.setLatestEventInfo(mContext, "Attachment downloaded", "Download complete", mNotificationResultIntent); return mNotification; }
From source file:barqsoft.footballscores.service.FetchScores.java
/** * Method to make a notification/*from www . ja v a 2 s .c om*/ */ public void notifyUser(String info) { Context context = getApplicationContext(); Resources resources = context.getResources(); //build your notification here. NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext()) .setColor(resources.getColor(R.color.green01)).setSmallIcon(R.drawable.ic_stat_name) .setContentTitle(getString(R.string.updated) + " " + info) .setContentText(getString(R.string.updated_descr)) .setStyle(new NotificationCompat.BigTextStyle().bigText(getString(R.string.updated_descr))) .setAutoCancel(true); // Intent ti open the app Intent intent = new Intent(getApplicationContext(), MainActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); //stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(intent); PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
From source file:org.zywx.wbpalmstar.platform.push.PushRecieveMsgReceiver.java
private void oldPushNotification(Context context, Intent intent) { PushReportUtility.log("oldPushNotification->isForground = " + EBrowserActivity.isForground); if (EBrowserActivity.isForground) { if (mContext != null) { intent.putExtra("ntype", F_TYPE_PUSH); ((EBrowserActivity) mContext).handleIntent(intent); }/* w w w. j a va2s . c om*/ } else { CharSequence tickerText = intent.getStringExtra("title"); // ???? Resources res = context.getResources(); int icon = res.getIdentifier("icon", "drawable", intent.getPackage()); long when = System.currentTimeMillis(); // ? // ??Nofification String notifyTitle = null; String pushMessage = intent.getStringExtra("message"); String value = intent.getStringExtra("data"); // ??json try { JSONObject bodyJson = new JSONObject(value); notifyTitle = bodyJson.getString("msgName");// ? } catch (Exception e) { PushReportUtility.oe("onReceive", e); } if (TextUtils.isEmpty(notifyTitle)) { notifyTitle = intent.getStringExtra("widgetName");// msgNamewidgetName? } if (TextUtils.isEmpty(notifyTitle)) { notifyTitle = "APPCAN";// widgetNameAPPCAN? } CharSequence contentTitle = notifyTitle; // ? Intent notificationIntent = new Intent(context, EBrowserActivity.class); // ??Activity notificationIntent.putExtra("data", value); notificationIntent.putExtra("message", pushMessage); notificationIntent.putExtra("ntype", F_TYPE_PUSH); String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns); Notification notification = new Notification(icon, tickerText, when); notification.flags = Notification.FLAG_AUTO_CANCEL; notification.defaults |= Notification.DEFAULT_SOUND; if (Build.VERSION.SDK_INT >= 16) { try { Field priorityField = Notification.class.getField("priority"); priorityField.setAccessible(true); priorityField.set(notification, 1); } catch (Exception e) { PushReportUtility.oe("onReceive", e); } } PendingIntent contentIntent = PendingIntent.getActivity(context, notificationNB, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(context, contentTitle, tickerText, contentIntent); // NotificationNotificationManager mNotificationManager.notify(notificationNB, notification); notificationNB++; } }
From source file:by.zatta.pilight.connection.ConnectionService.java
private static void makeNotification(NotificationType type, String message) { Intent main;/*from ww w . j a va 2s. co m*/ Intent kill; PendingIntent sentBroadcast; PendingIntent startMainActivity; PendingIntent killService; String myDate = java.text.DateFormat.getTimeInstance().format(Calendar.getInstance().getTime()); //Log.v(TAG, "setting notification: " + type.name() + " while current = " + mCurrentNotif.name()); if (type != mCurrentNotif) { //Log.v(TAG, "setting NEW notification: " + type.name()); sendMessageToUI(MSG_SET_STATUS, type.name()); switch (type) { case DESTROYED: builder = new Notification.Builder(ctx); builder.setSmallIcon(R.drawable.eye_black).setLargeIcon(bigPic(R.drawable.eye_black)) .setContentTitle(aCtx.getString(R.string.app_name)).setContentText(message); mCurrentNotif = NotificationType.DESTROYED; break; case CONNECTING: kill = new Intent("pilight-kill-service"); killService = PendingIntent.getBroadcast(ctx, 0, kill, PendingIntent.FLAG_UPDATE_CURRENT); builder = new Notification.Builder(ctx).setContentTitle(aCtx.getString(R.string.app_name)) .setContentText(message).setDeleteIntent(killService).setSmallIcon(R.drawable.eye_trans) .setLargeIcon(bigPic(R.drawable.eye_trans)); mCurrentNotif = NotificationType.CONNECTING; break; case CONNECTED: main = new Intent(ctx, MainActivity.class); main.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); startMainActivity = PendingIntent.getActivity(ctx, 0, main, PendingIntent.FLAG_UPDATE_CURRENT); builder = new Notification.Builder(ctx).setContentTitle(aCtx.getString(R.string.app_name)) .setContentText(message + "\n" + myDate).setContentIntent(startMainActivity) .setSmallIcon(R.drawable.eye_white).setLargeIcon(bigPic(R.drawable.eye_white)); mCurrentNotif = NotificationType.CONNECTED; break; case FAILED: main = new Intent("pilight-reconnect"); sentBroadcast = PendingIntent.getBroadcast(ctx, 0, main, PendingIntent.FLAG_UPDATE_CURRENT); kill = new Intent("pilight-kill-service"); killService = PendingIntent.getBroadcast(ctx, 0, kill, PendingIntent.FLAG_UPDATE_CURRENT); builder = new Notification.Builder(ctx).setContentTitle("pilight") .setContentText(aCtx.getString(R.string.noti_failed)).setDeleteIntent(killService) .addAction(R.drawable.action_refresh, aCtx.getString(R.string.noti_retry), sentBroadcast) .setSmallIcon(R.drawable.eye_trans).setLargeIcon(bigPic(R.drawable.eye_trans)); mCurrentNotif = NotificationType.FAILED; break; case LOST_CONNECTION: main = new Intent("pilight-reconnect"); sentBroadcast = PendingIntent.getBroadcast(ctx, 0, main, PendingIntent.FLAG_UPDATE_CURRENT); kill = new Intent("pilight-kill-service"); killService = PendingIntent.getBroadcast(ctx, 0, kill, PendingIntent.FLAG_UPDATE_CURRENT); builder = new Notification.Builder(ctx).setContentTitle(aCtx.getString(R.string.app_name)) .setContentText(message + "\n" + myDate).setDeleteIntent(killService) .addAction(R.drawable.action_refresh, aCtx.getString(R.string.noti_retry), sentBroadcast) .setSmallIcon(R.drawable.eye_trans).setLargeIcon(bigPic(R.drawable.eye_trans)); mCurrentNotif = NotificationType.LOST_CONNECTION; break; case UPDATE: main = new Intent(ctx, MainActivity.class); main.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); startMainActivity = PendingIntent.getActivity(ctx, 0, main, PendingIntent.FLAG_UPDATE_CURRENT); String[] title = message.split("\n"); message = message.replace(title[0] + "\n", ""); builder = new Notification.Builder(ctx).setContentTitle(title[0]).setContentText(message) .setStyle(new Notification.BigTextStyle().bigText(message)) .setContentIntent(startMainActivity).setSmallIcon(R.drawable.eye_white) .setLargeIcon(bigPic(R.drawable.eye_white)); mCurrentNotif = NotificationType.UPDATE; break; default: break; } } else { if (message != null) { if (message.contains("Stamp")) { String[] title = message.split("\n"); message = message.replace(title[0] + "\n", ""); builder.setContentTitle(title[0]).setStyle(new Notification.BigTextStyle().bigText(message)); builder.setContentText(message); } else { builder.setContentTitle(myDate).setStyle(new Notification.BigTextStyle().bigText(message)); builder.setContentText(message); } } } mNotMan.notify(35, builder.build()); }
From source file:com.easibeacon.examples.shop.MainActivity.java
public void createNotification(String title, String content, String monumentId) { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext()) .setSmallIcon(R.drawable.notification).setContentTitle(title).setContentText(content); Intent resultIntent = new Intent(getApplicationContext(), MonumentActivity.class); Log.i("Monument", monumentId); resultIntent.putExtra("id", monumentId); PendingIntent resultPendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); mNotifyMgr.notify(Integer.parseInt(monumentId), mBuilder.build()); //arrayAdapter.notifyDataSetChanged(); }
From source file:com.siahmsoft.soundroid.sdk7.services.UploadService.java
/** * Show a notification while this service is running. *//*from w w w.j ava 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:name.gumartinm.weather.information.widget.WidgetIntentService.java
private RemoteViews makeView(final Current current, final WeatherLocation weatherLocation, final int appWidgetId) { // 1. Update units of measurement. UnitsConversor tempUnitsConversor;/*ww w .jav a 2 s . com*/ String keyPreference = this.getApplicationContext() .getString(R.string.widget_preferences_temperature_units_key); String realKeyPreference = keyPreference + "_" + appWidgetId; // What was saved to permanent storage (or default values if it is the first time) final int tempValue = this.getSharedPreferences(WIDGET_PREFERENCES_NAME, Context.MODE_PRIVATE) .getInt(realKeyPreference, 0); final String tempSymbol = this.getResources() .getStringArray(R.array.weather_preferences_temperature)[tempValue]; if (tempValue == 0) { tempUnitsConversor = new UnitsConversor() { @Override public double doConversion(final double value) { return value - 273.15; } }; } else if (tempValue == 1) { tempUnitsConversor = new UnitsConversor() { @Override public double doConversion(final double value) { return (value * 1.8) - 459.67; } }; } else { tempUnitsConversor = new UnitsConversor() { @Override public double doConversion(final double value) { return value; } }; } // 2. Update country. keyPreference = this.getApplicationContext().getString(R.string.widget_preferences_country_switch_key); realKeyPreference = keyPreference + "_" + appWidgetId; // What was saved to permanent storage (or default values if it is the first time) final boolean isCountry = this.getSharedPreferences(WIDGET_PREFERENCES_NAME, Context.MODE_PRIVATE) .getBoolean(realKeyPreference, false); // 3. Formatters final DecimalFormat tempFormatter = (DecimalFormat) NumberFormat.getNumberInstance(Locale.US); tempFormatter.applyPattern("###.##"); // 4. Prepare data for RemoteViews. String tempMax = ""; if (current.getMain().getTemp_max() != null) { double conversion = (Double) current.getMain().getTemp_max(); conversion = tempUnitsConversor.doConversion(conversion); tempMax = tempFormatter.format(conversion) + tempSymbol; } String tempMin = ""; if (current.getMain().getTemp_min() != null) { double conversion = (Double) current.getMain().getTemp_min(); conversion = tempUnitsConversor.doConversion(conversion); tempMin = tempFormatter.format(conversion) + tempSymbol; } Bitmap picture; if ((current.getWeather().size() > 0) && (current.getWeather().get(0).getIcon() != null) && (IconsList.getIcon(current.getWeather().get(0).getIcon()) != null)) { final String icon = current.getWeather().get(0).getIcon(); picture = BitmapFactory.decodeResource(this.getResources(), IconsList.getIcon(icon).getResourceDrawable()); } else { picture = BitmapFactory.decodeResource(this.getResources(), R.drawable.weather_severe_alert); } final String city = weatherLocation.getCity(); final String country = weatherLocation.getCountry(); // 5. Insert data in RemoteViews. final RemoteViews remoteView = new RemoteViews(this.getApplicationContext().getPackageName(), R.layout.appwidget); remoteView.setImageViewBitmap(R.id.weather_appwidget_image, picture); remoteView.setTextViewText(R.id.weather_appwidget_temperature_max, tempMax); remoteView.setTextViewText(R.id.weather_appwidget_temperature_min, tempMin); remoteView.setTextViewText(R.id.weather_appwidget_city, city); if (!isCountry) { remoteView.setViewVisibility(R.id.weather_appwidget_country, View.GONE); } else { // TODO: It is as if Android had a view cache. If I did not set VISIBLE value, // the country field would be gone forever... :/ remoteView.setViewVisibility(R.id.weather_appwidget_country, View.VISIBLE); remoteView.setTextViewText(R.id.weather_appwidget_country, country); } // 6. Activity launcher. final Intent resultIntent = new Intent(this.getApplicationContext(), WidgetConfigure.class); resultIntent.putExtra("actionFromUser", true); resultIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); // From: http://stackoverflow.com/questions/4011178/multiple-instances-of-widget-only-updating-last-widget final Uri data = Uri.withAppendedPath(Uri.parse("PAIN" + "://widget/id/"), String.valueOf(appWidgetId)); resultIntent.setData(data); final TaskStackBuilder stackBuilder = TaskStackBuilder.create(this.getApplicationContext()); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(WidgetConfigure.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(resultIntent); final PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); remoteView.setOnClickPendingIntent(R.id.weather_appwidget, resultPendingIntent); return remoteView; }
From source file:no.firestorm.weathernotificatonservice.WeatherNotificationService.java
private void removeAlarm() { final PendingIntent pendingIntent = PendingIntent.getService(this, 0, new Intent(this, WeatherNotificationService.class), PendingIntent.FLAG_UPDATE_CURRENT); final AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE); alarm.cancel(pendingIntent);/* w ww. ja v a 2s.c o m*/ }