Example usage for android.app PendingIntent FLAG_UPDATE_CURRENT

List of usage examples for android.app PendingIntent FLAG_UPDATE_CURRENT

Introduction

In this page you can find the example usage for android.app PendingIntent FLAG_UPDATE_CURRENT.

Prototype

int FLAG_UPDATE_CURRENT

To view the source code for android.app PendingIntent FLAG_UPDATE_CURRENT.

Click Source Link

Document

Flag indicating that if the described PendingIntent already exists, then keep it but replace its extra data with what is in this new Intent.

Usage

From source file:com.swetha.easypark.GetIndividualParkingSpotDetails.java

private void scheduleNotification(Notification notification) {

    Intent notificationIntent = new Intent(this, NotificationPublisher.class);
    notificationIntent.putExtra(NotificationPublisher.NOTIFICATION_ID, Integer.parseInt(theParkingSpotId));
    notificationIntent.putExtra(NotificationPublisher.NOTIFICATION, notification);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    long currentTimeInLong = DateTimeHelpers
            .convertToLongFromTime(DateTimeHelpers.dtf.format(new Date()).toString());
    long delay = toTime - (currentTimeInLong + Constants.tenMinutesInMilliseconds);
    long futureInMills = SystemClock.elapsedRealtime() + delay;

    Log.i("GetIndividualParkingSpotDetails", " Spot has been blocked till long " + toTime);
    Log.i("GetIndividualParkingSpotDetails",
            " Spot has been blocked till  DateTime" + DateTimeHelpers.convertToTimeFromLong(toTime));

    Log.i("GetIndividualParkingSpotDetails", " CurrentTime in  long " + currentTimeInLong);
    Log.i("GetIndividualParkingSpotDetails",
            " Spot has been blocked till  DateTime" + DateTimeHelpers.convertToTimeFromLong(currentTimeInLong));

    Log.i("GetIndividualParkingSpotDetails", "value of delay" + delay);
    Log.i("GetIndividualParkingSpotDetails",
            "value of mills in time" + DateTimeHelpers.convertToTimeFromLong(futureInMills));

    Log.i("GetIndividualParkingSpotDetails", "Notification is kept at this mills" + futureInMills);
    AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, futureInMills, pendingIntent);

}

From source file:ca.zadrox.dota2esportticker.service.UpdateMatchService.java

private void cancelAutoUpdate() {
    final Intent updateMatchIntent = new Intent(UpdateMatchService.ACTION_AUTO_UPDATE_MATCHES, null, this,
            UpdateMatchService.class);

    final Intent updateResultIntent = new Intent(UpdateMatchService.ACTION_UPDATE_RESULTS, null, this,
            UpdateMatchService.class);

    PendingIntent umi = PendingIntent.getService(this.getApplicationContext(), 0, updateMatchIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    PendingIntent uri = PendingIntent.getService(this.getApplicationContext(), 0, updateResultIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    final AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);

    am.cancel(umi);//w  w w. j  a  va 2  s .c o m
    am.cancel(uri);
}

From source file:ch.nexuscomputing.android.osciprimeics.OsciPrimeService.java

private void notifyService() {
    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    Intent ni = new Intent(this, OsciPrimeICSActivity.class);
    ni.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pi = PendingIntent.getActivity(this, 0, ni, PendingIntent.FLAG_UPDATE_CURRENT);
    // Bitmap tmp = BitmapFactory.decodeResource(getResources(),
    // R.drawable.notification);
    // sNotification.contentIntent = pi;
    // sNotification.flags = Notification.FLAG_ONGOING_EVENT;
    // sNotification.icon = R.drawable.notification;
    // sNotification.setLatestEventInfo(this, "OsciPrime",
    // "Collecting Data",
    // pi);// w ww . ja  va  2s  .  c  o  m

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

    builder.setContentIntent(pi).setSmallIcon(R.drawable.notification).setTicker("Collecting Data")
            .setOngoing(true).setWhen(System.currentTimeMillis()).setAutoCancel(false)
            .setContentTitle("OsciPrime").setContentText("Collecting Data");
    sNotification = builder.getNotification();
    nm.notify(NOTIFICATION_ID, sNotification);
}

From source file:com.ble.BLService.java

@Override
public IBinder onBind(Intent intent) {
    mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle("BLE Stm32").setContentText("").setAutoCancel(true);
    mNotificationId = 001;//  ww w .  ja va  2 s .c o m
    Intent resultIntent = new Intent(this, BLESelect.class);

    //NOTIFICATION INTENTE
    resultPendingIntent = PendingIntent.getActivity(this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    mBuilder.setContentIntent(resultPendingIntent);
    mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    return mBinder;
}

From source file:com.android.deskclock.timer.TimerReceiver.java

private void updateNextTimesup(Context context) {
    TimerObj t = getNextRunningTimer(mTimers, false, Utils.getTimeNow());
    long nextTimesup = (t == null) ? -1 : t.getTimesupTime();
    int timerId = (t == null) ? -1 : t.mTimerId;

    Intent intent = new Intent();
    intent.setAction(Timers.TIMES_UP);//from w  w  w  .  j a v a  2 s  . c  o m
    intent.setClass(context, TimerReceiver.class);
    // Time-critical, should be foreground
    intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    if (!mTimers.isEmpty()) {
        intent.putExtra(Timers.TIMER_INTENT_EXTRA, timerId);
    }
    AlarmManager mngr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    PendingIntent p = PendingIntent.getBroadcast(context, 0, intent,
            PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT);
    if (t != null) {
        if (Utils.isKitKatOrLater()) {
            mngr.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, nextTimesup, p);
        } else {
            mngr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, nextTimesup, p);
        }
        if (Timers.LOGGING) {
            Log.d(TAG, "Setting times up to " + nextTimesup);
        }
    } else {
        // if no timer is found Pending Intents should be canceled
        // to keep the internal state consistent with the UI
        mngr.cancel(p);
        p.cancel();
        if (Timers.LOGGING) {
            Log.v(TAG, "no next times up");
        }
    }
}

From source file:com.androidinspain.deskclock.alarms.AlarmStateManager.java

/**
 * Used in L and later devices where "next alarm" is stored in the Alarm Manager.
 *//*www .jav  a2 s .com*/
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static void updateNextAlarmInAlarmManager(Context context, AlarmInstance nextAlarm) {
    // Sets a surrogate alarm with alarm manager that provides the AlarmClockInfo for the
    // alarm that is going to fire next. The operation is constructed such that it is ignored
    // by AlarmStateManager.

    final AlarmManager alarmManager = (AlarmManager) context.getSystemService(ALARM_SERVICE);

    final int flags = nextAlarm == null ? PendingIntent.FLAG_NO_CREATE : 0;
    final PendingIntent operation = PendingIntent.getBroadcast(context, 0 /* requestCode */,
            AlarmStateManager.createIndicatorIntent(context), flags);

    if (nextAlarm != null) {
        LogUtils.i("Setting upcoming AlarmClockInfo for alarm: " + nextAlarm.mId);
        long alarmTime = nextAlarm.getAlarmTime().getTimeInMillis();

        // Create an intent that can be used to show or edit details of the next alarm.
        PendingIntent viewIntent = PendingIntent.getActivity(context, nextAlarm.hashCode(),
                AlarmNotifications.createViewAlarmIntent(context, nextAlarm),
                PendingIntent.FLAG_UPDATE_CURRENT);

        final AlarmClockInfo info = new AlarmClockInfo(alarmTime, viewIntent);
        Utils.updateNextAlarm(alarmManager, info, operation);
    } else if (operation != null) {
        LogUtils.i("Canceling upcoming AlarmClockInfo");
        alarmManager.cancel(operation);
    }
}

From source file:com.bayapps.android.robophish.MusicService.java

@Override
public void onCreate() {
    super.onCreate();
    LogHelper.d(TAG, "onCreate");

    mMusicProvider = new MusicProvider();

    // To make the app more responsive, fetch and cache catalog information now.
    // This can help improve the response time in the method
    // {@link #onLoadChildren(String, Result<List<MediaItem>>) onLoadChildren()}.
    //mMusicProvider.retrieveMediaAsync(null /* Callback */);

    mPackageValidator = new PackageValidator(this);

    QueueManager queueManager = new QueueManager(mMusicProvider, getResources(),
            new QueueManager.MetadataUpdateListener() {
                @Override/* w ww .j  ava2  s .  c  om*/
                public void onMetadataChanged(MediaMetadataCompat metadata) {
                    mSession.setMetadata(metadata);
                }

                @Override
                public void onMetadataRetrieveError() {
                    mPlaybackManager.updatePlaybackState(getString(R.string.error_no_metadata));
                }

                @Override
                public void onCurrentQueueIndexUpdated(int queueIndex) {
                    mPlaybackManager.handlePlayRequest();
                }

                @Override
                public void onQueueUpdated(String title, List<MediaSessionCompat.QueueItem> newQueue) {
                    mSession.setQueue(newQueue);
                    mSession.setQueueTitle(title);
                }
            });

    LocalPlayback playback = new LocalPlayback(this, mMusicProvider);
    mPlaybackManager = new PlaybackManager(this, getResources(), mMusicProvider, queueManager, playback);

    // Start a new MediaSession
    mSession = new MediaSessionCompat(this, "MusicService");
    setSessionToken(mSession.getSessionToken());
    mSession.setCallback(mPlaybackManager.getMediaSessionCallback());
    mSession.setFlags(
            MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);

    Context context = getApplicationContext();
    Intent intent = new Intent(context, NowPlayingActivity.class);
    PendingIntent pi = PendingIntent.getActivity(context, 99 /*request code*/, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    mSession.setSessionActivity(pi);

    mSessionExtras = new Bundle();
    CarHelper.setSlotReservationFlags(mSessionExtras, true, true, true);
    WearHelper.setSlotReservationFlags(mSessionExtras, true, true);
    WearHelper.setUseBackgroundFromTheme(mSessionExtras, true);
    mSession.setExtras(mSessionExtras);

    mPlaybackManager.updatePlaybackState(null);

    try {
        mMediaNotificationManager = new MediaNotificationManager(this);
    } catch (RemoteException e) {
        throw new IllegalStateException("Could not create a MediaNotificationManager", e);
    }
    VideoCastManager.getInstance().addVideoCastConsumer(mCastConsumer);
    mMediaRouter = MediaRouter.getInstance(getApplicationContext());

    registerCarConnectionReceiver();
}

From source file:com.samknows.measurement.test.TestExecutor.java

@SuppressWarnings("deprecation")
public void showNotification(String message) {
    String title = tc.getString(R.string.ntf_title);

    NotificationManager manager = (NotificationManager) tc.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification n = new Notification(R.drawable.icon, message, System.currentTimeMillis());
    PendingIntent intent = PendingIntent.getService(tc.getServiceContext(), Constants.RC_NOTIFICATION,
            new Intent(), PendingIntent.FLAG_UPDATE_CURRENT);
    n.setLatestEventInfo(tc.getServiceContext(), title, message, intent);
    manager.notify(Constants.NOTIFICATION_ID, n);
}

From source file:com.actinarium.nagbox.service.NagboxService.java

private void rescheduleAlarm() {
    AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

    // Prepare pending intent. Setting, updating, or cancelling the alarm - we need it in either case
    Intent intent = new Intent(this, NagAlarmReceiver.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    long nextTimestamp = NagboxDbOps.getClosestNagTimestamp(mDatabase);
    if (nextTimestamp == 0) {
        alarmManager.cancel(pendingIntent);
    } else {//from  w  ww  .  j a v a 2 s .  c  om
        // todo: deal with exact/inexact reminders later
        if (Build.VERSION.SDK_INT >= 23) {
            alarmManager.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, nextTimestamp, pendingIntent);
        } else if (Build.VERSION.SDK_INT >= 19) {
            alarmManager.setWindow(AlarmManager.RTC_WAKEUP, nextTimestamp, ALARM_TOLERANCE, pendingIntent);
        } else {
            alarmManager.set(AlarmManager.RTC_WAKEUP, nextTimestamp, pendingIntent);
        }
    }
}

From source file:com.ayogo.cordova.notification.ScheduledNotificationManager.java

public void showNotification(ScheduledNotification scheduledNotification) {
    LOG.v(NotificationPlugin.TAG, "showNotification: " + scheduledNotification.toString());

    NotificationManager nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);

    // Build the notification options
    builder.setDefaults(Notification.DEFAULT_ALL).setTicker(scheduledNotification.body)
            .setPriority(Notification.PRIORITY_HIGH).setAutoCancel(true);

    // TODO: add sound support
    // if (scheduledNotification.sound != null) {
    //     builder.setSound(sound);
    // }/*from  www  .j a va2 s. c  om*/

    if (scheduledNotification.body != null) {
        builder.setContentTitle(scheduledNotification.title);
        builder.setContentText(scheduledNotification.body);
        builder.setStyle(new NotificationCompat.BigTextStyle().bigText(scheduledNotification.body));
    } else {
        //Default the title to the app name
        try {
            PackageManager pm = context.getPackageManager();
            ApplicationInfo applicationInfo = pm.getApplicationInfo(context.getPackageName(),
                    PackageManager.GET_META_DATA);

            String appName = applicationInfo.loadLabel(pm).toString();

            builder.setContentTitle(appName);
            builder.setContentText(scheduledNotification.title);
            builder.setStyle(new NotificationCompat.BigTextStyle().bigText(scheduledNotification.title));
        } catch (NameNotFoundException e) {
            LOG.v(NotificationPlugin.TAG, "Failed to set title for notification!");
            return;
        }
    }

    if (scheduledNotification.badge != null) {
        LOG.v(NotificationPlugin.TAG, "showNotification: has a badge!");
        builder.setSmallIcon(getResIdForDrawable(scheduledNotification.badge));
    } else {
        LOG.v(NotificationPlugin.TAG, "showNotification: has no badge, use app icon!");
        try {
            PackageManager pm = context.getPackageManager();
            ApplicationInfo applicationInfo = pm.getApplicationInfo(context.getPackageName(),
                    PackageManager.GET_META_DATA);
            Resources resources = pm.getResourcesForApplication(applicationInfo);
            builder.setSmallIcon(applicationInfo.icon);
        } catch (NameNotFoundException e) {
            LOG.v(NotificationPlugin.TAG, "Failed to set badge for notification!");
            return;
        }
    }

    if (scheduledNotification.icon != null) {
        LOG.v(NotificationPlugin.TAG, "showNotification: has an icon!");
        builder.setLargeIcon(getIconFromUri(scheduledNotification.icon));
    } else {
        LOG.v(NotificationPlugin.TAG, "showNotification: has no icon, use app icon!");
        try {
            PackageManager pm = context.getPackageManager();
            ApplicationInfo applicationInfo = pm.getApplicationInfo(context.getPackageName(),
                    PackageManager.GET_META_DATA);
            Resources resources = pm.getResourcesForApplication(applicationInfo);
            Bitmap appIconBitmap = BitmapFactory.decodeResource(resources, applicationInfo.icon);
            builder.setLargeIcon(appIconBitmap);
        } catch (NameNotFoundException e) {
            LOG.v(NotificationPlugin.TAG, "Failed to set icon for notification!");
            return;
        }
    }

    Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
    launchIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    launchIntent.setAction("notification");

    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, launchIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(contentIntent);

    Notification notification = builder.build();

    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    LOG.v(NotificationPlugin.TAG, "notify!");
    notificationManager.notify(scheduledNotification.tag.hashCode(), notification);
}