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:at.vcity.androidimsocket.services.IMService.java
@Override public void onDestroy() { try {/*from ww w.ja v a2s .c o m*/ unregisterReceiver(alarmReceiver); } catch (IllegalArgumentException e) { } AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(this, IMService.class); PendingIntent pintent = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); alarm.cancel(pintent); Log.i("IMService is being destroyed", "..."); // super.onDestroy(); }
From source file:com.android.deskclock.data.TimerModel.java
/** * Updates the callback given to this application from the {@link AlarmManager} that signals the * expiration of the next timer. If no timers are currently set to expire (i.e. no running * timers exist) then this method clears the expiration callback from AlarmManager. *//*from ww w. j a v a 2 s .c o m*/ private void updateAlarmManager() { // Locate the next firing timer if one exists. Timer nextExpiringTimer = null; for (Timer timer : getMutableTimers()) { if (timer.isRunning()) { if (nextExpiringTimer == null) { nextExpiringTimer = timer; } else if (timer.getExpirationTime() < nextExpiringTimer.getExpirationTime()) { nextExpiringTimer = timer; } } } // Build the intent that signals the timer expiration. final Intent intent = TimerService.createTimerExpiredIntent(mContext, nextExpiringTimer); if (nextExpiringTimer == null) { // Cancel the existing timer expiration callback. final PendingIntent pi = PendingIntent.getService(mContext, 0, intent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_NO_CREATE); if (pi != null) { mAlarmManager.cancel(pi); pi.cancel(); } } else { // Update the existing timer expiration callback. final PendingIntent pi = PendingIntent.getService(mContext, 0, intent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT); schedulePendingIntent(nextExpiringTimer.getExpirationTime(), pi); } }
From source file:com.android.deskclock.timer.TimerReceiver.java
private void showTimesUpNotification(final Context context, TimerObj timerObj) { // Content Intent. When clicked will show the timer full screen PendingIntent contentIntent = PendingIntent.getActivity(context, timerObj.mTimerId, new Intent(context, TimerAlertFullScreen.class).putExtra(Timers.TIMER_INTENT_EXTRA, timerObj.mTimerId),//from w w w .j a va2s . c om PendingIntent.FLAG_UPDATE_CURRENT); // Add one minute action button PendingIntent addOneMinuteAction = PendingIntent.getBroadcast(context, timerObj.mTimerId, new Intent(Timers.NOTIF_TIMES_UP_PLUS_ONE).putExtra(Timers.TIMER_INTENT_EXTRA, timerObj.mTimerId), PendingIntent.FLAG_UPDATE_CURRENT); // Add stop/done action button PendingIntent stopIntent = PendingIntent.getBroadcast(context, timerObj.mTimerId, new Intent(Timers.NOTIF_TIMES_UP_STOP).putExtra(Timers.TIMER_INTENT_EXTRA, timerObj.mTimerId), PendingIntent.FLAG_UPDATE_CURRENT); // Notification creation final NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setContentIntent(contentIntent) .addAction(R.drawable.ic_add_24dp, context.getResources().getString(R.string.timer_plus_1_min), addOneMinuteAction) .addAction( timerObj.getDeleteAfterUse() ? android.R.drawable.ic_menu_close_clear_cancel : R.drawable.ic_stop_24dp, timerObj.getDeleteAfterUse() ? context.getResources().getString(R.string.timer_done) : context.getResources().getString(R.string.timer_stop), stopIntent) .setContentTitle(timerObj.getLabelOrDefault(context)) .setContentText(context.getResources().getString(R.string.timer_times_up)) .setSmallIcon(R.drawable.stat_notify_timer).setOngoing(true).setAutoCancel(false) .setPriority(NotificationCompat.PRIORITY_MAX).setDefaults(NotificationCompat.DEFAULT_LIGHTS) .setWhen(0); // Send the notification using the timer's id to identify the // correct notification NotificationManagerCompat.from(context).notify(timerObj.mTimerId, builder.build()); if (Timers.LOGGING) { Log.v(TAG, "Setting times-up notification for " + timerObj.getLabelOrDefault(context) + " #" + timerObj.mTimerId); } }
From source file:it.feio.android.omninotes.async.DataBackupIntentService.java
/** * Creation of notification on operations completed *//*from w ww . jav a2s .c o m*/ private void createNotification(Intent intent, Context mContext, String title, String message, File backupDir) { // The behavior differs depending on intent action Intent intentLaunch; if (DataBackupIntentService.ACTION_DATA_IMPORT.equals(intent.getAction()) || DataBackupIntentService.ACTION_DATA_IMPORT_SPRINGPAD.equals(intent.getAction())) { intentLaunch = new Intent(mContext, MainActivity.class); intentLaunch.setAction(Constants.ACTION_RESTART_APP); } else { intentLaunch = new Intent(); } // Add this bundle to the intent intentLaunch.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intentLaunch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // Creates the PendingIntent PendingIntent notifyIntent = PendingIntent.getActivity(mContext, 0, intentLaunch, PendingIntent.FLAG_UPDATE_CURRENT); NotificationsHelper mNotificationsHelper = new NotificationsHelper(mContext); mNotificationsHelper.createNotification(R.drawable.ic_content_save_white_24dp, title, notifyIntent) .setMessage(message).setRingtone(prefs.getString("settings_notification_ringtone", null)) .setLedActive(); if (prefs.getBoolean("settings_notification_vibration", true)) mNotificationsHelper.setVibration(); mNotificationsHelper.show(); }
From source file:com.bangz.smartmute.services.LocationMuteService.java
private PendingIntent getGeofencesPendingIntent(Context context) { Intent intent = new Intent(ACTION_GEODEFENCE_TRIGGER, null, context, LocationMuteService.class); return PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); }
From source file:com.android.messaging.ui.UIIntentsImpl.java
@Override public PendingIntent getPendingIntentForLowStorageNotifications(final Context context) { final TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context); final Intent conversationListIntent = getConversationListActivityIntent(context); taskStackBuilder.addNextIntent(conversationListIntent); taskStackBuilder.addNextIntentWithParentStack(getSmsStorageLowWarningActivityIntent(context)); return taskStackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); }
From source file:com.adkdevelopment.earthquakesurvival.data.syncadapter.SyncAdapter.java
/** * Raises a notification with a biggest earthquake with each sync * * @param notifyValues data with the biggest recent earthquake *///from www . j a va2 s .co m private void sendNotification(ContentValues notifyValues) { Context context = getContext(); if (Utilities.getNotificationsPrefs(context) && !Utilities.checkForeground(context)) { //checking the last update and notify if it' the first of the day SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); String lastNotificationKey = context.getString(R.string.sharedprefs_key_lastnotification); long lastSync = prefs.getLong(lastNotificationKey, 0); if (System.currentTimeMillis() - lastSync >= DateUtils.DAY_IN_MILLIS) { Intent intent = new Intent(context, DetailActivity.class); double latitude = notifyValues.getAsDouble(EarthquakeColumns.LATITUDE); double longitude = notifyValues.getAsDouble(EarthquakeColumns.LONGITUDE); LatLng latLng = new LatLng(latitude, longitude); String distance = context.getString(R.string.earthquake_distance, LocationUtils.getDistance(latLng, LocationUtils.getLocation(context))); String magnitude = context.getString(R.string.earthquake_magnitude, notifyValues.getAsDouble(EarthquakeColumns.MAG)); String date = Utilities.getRelativeDate(notifyValues.getAsLong(EarthquakeColumns.TIME)); double depth = notifyValues.getAsDouble(EarthquakeColumns.DEPTH); intent.putExtra(Feature.MAGNITUDE, notifyValues.getAsDouble(EarthquakeColumns.MAG)); intent.putExtra(Feature.PLACE, notifyValues.getAsString(EarthquakeColumns.PLACE)); intent.putExtra(Feature.DATE, date); intent.putExtra(Feature.LINK, notifyValues.getAsString(EarthquakeColumns.URL)); intent.putExtra(Feature.LATLNG, latLng); intent.putExtra(Feature.DISTANCE, distance); intent.putExtra(Feature.DEPTH, depth); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(context, EarthquakeObject.NOTIFICATION_ID_1, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(context); Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher); builder.setDefaults(Notification.DEFAULT_ALL).setAutoCancel(true) .setContentTitle(context.getString(R.string.earthquake_statistics_largest)) .setContentText(context.getString(R.string.earthquake_magnitude, notifyValues.get(EarthquakeColumns.MAG))) .setContentIntent(pendingIntent).setSmallIcon(R.drawable.ic_info_black_24dp) .setLargeIcon(largeIcon).setTicker(context.getString(R.string.app_name)) .setStyle(new NotificationCompat.BigTextStyle() .bigText(notifyValues.get(EarthquakeColumns.PLACE).toString() + "\n" + magnitude + "\n" + context.getString(R.string.earthquake_depth, depth) + "\n" + distance + "\n" + date)) .setGroup(EarthquakeObject.NOTIFICATION_GROUP).setGroupSummary(true); NotificationManagerCompat managerCompat = NotificationManagerCompat.from(context); managerCompat.notify(EarthquakeObject.NOTIFICATION_ID_1, builder.build()); //refreshing last sync boolean success = prefs.edit().putLong(lastNotificationKey, System.currentTimeMillis()).commit(); } } }
From source file:at.vcity.androidimsocket.services.IMService.java
public void receiveFriendReq(Object... args) { try {/*from w w w . java 2s. co m*/ JSONObject params = new JSONObject(args[0].toString()); JSONArray friendarray = params.getJSONArray(FriendInfo.FRIEND_LIST); ArrayList<FriendInfo> unapprovedfriends = new ArrayList<FriendInfo>(); for (int i = 0; i < friendarray.length(); i++) { JSONObject friend = friendarray.getJSONObject(i); FriendInfo f = new FriendInfo(); f.userId = friend.getString(FriendInfo.USER_ID); f.userName = friend.getString(FriendInfo.USERNAME); unapprovedfriends.add(f); } FriendController.setUnapprovedFriendsInfo(unapprovedfriends); String title = "AndroidIM: You got friend request(s)! "; NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.stat_sample).setContentTitle(title).setAutoCancel(true); //.setContentText(text); Intent i = new Intent(this, UnApprovedFriendList.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT); // Set the info for the views that show in the notification panel. // msg.length()>15 ? MSG : msg.substring(0, 15); mBuilder.setContentIntent(contentIntent); //TODO: it can be improved, for instance message coming from same user may be concatenated // next version // Send the notification. // We use a layout id because it is a unique number. We use it later to cancel. mNM.notify(R.string.new_friend_request_exist, mBuilder.build()); } catch (JSONException e) { } }
From source file:biz.bokhorst.bpt.BPTService.java
private Notification getNotification(String text) { // Build intent Intent toLaunch = new Intent(this, BackPackTrack.class); toLaunch.setAction("android.intent.action.MAIN"); toLaunch.addCategory("android.intent.category.LAUNCHER"); toLaunch.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); // Build pending intent PendingIntent intentBack = PendingIntent.getActivity(this, 0, toLaunch, PendingIntent.FLAG_UPDATE_CURRENT); // Build result intent update Intent resultIntentUpdate = new Intent(this, BPTService.class); resultIntentUpdate.setAction("Update"); // Build pending intent waypoint PendingIntent pendingIntentUpdate = PendingIntent.getService(this, 2, resultIntentUpdate, PendingIntent.FLAG_UPDATE_CURRENT); // Build result intent waypoint Intent resultIntentWaypoint = new Intent(this, BPTService.class); resultIntentWaypoint.setAction("Waypoint"); // Build pending intent waypoint PendingIntent pendingIntentWaypoint = PendingIntent.getService(this, 2, resultIntentWaypoint, PendingIntent.FLAG_UPDATE_CURRENT); // Build notification NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder.setSmallIcon(R.drawable.icon); notificationBuilder.setContentTitle(getString(R.string.app_name)); notificationBuilder.setContentText(text); notificationBuilder.setContentIntent(intentBack); notificationBuilder.setWhen(System.currentTimeMillis()); notificationBuilder.setAutoCancel(true); notificationBuilder.addAction(android.R.drawable.ic_menu_mylocation, getString(R.string.Update), pendingIntentUpdate);//from w ww . ja v a 2 s .com notificationBuilder.addAction(android.R.drawable.ic_menu_add, getString(R.string.Waypoint), pendingIntentWaypoint); Notification notification = notificationBuilder.build(); return notification; }
From source file:com.dycody.android.idealnote.async.DataBackupIntentService.java
/** * Creation of notification on operations completed *///from ww w.j a va2 s .c om private void createNotification(Intent intent, Context mContext, String title, String message, File backupDir) { // The behavior differs depending on intent action Intent intentLaunch; if (DataBackupIntentService.ACTION_DATA_IMPORT.equals(intent.getAction()) || DataBackupIntentService.ACTION_DATA_IMPORT_SPRINGPAD.equals(intent.getAction())) { intentLaunch = new Intent(mContext, MainActivity.class); intentLaunch.setAction(Constants.ACTION_RESTART_APP); } else { intentLaunch = new Intent(); } // Add this bundle to the intent intentLaunch.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intentLaunch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // Creates the PendingIntent PendingIntent notifyIntent = PendingIntent.getActivity(mContext, 0, intentLaunch, PendingIntent.FLAG_UPDATE_CURRENT); NotificationsHelper mNotificationsHelper = new NotificationsHelper(mContext); mNotificationsHelper .createNotification(com.dycody.android.idealnote.R.drawable.ic_content_save_white_24dp, title, notifyIntent) .setMessage(message).setRingtone(prefs.getString("settings_notification_ringtone", null)) .setLedActive(); if (prefs.getBoolean("settings_notification_vibration", true)) mNotificationsHelper.setVibration(); mNotificationsHelper.show(); }