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.android.messaging.ui.UIIntentsImpl.java

@Override
public PendingIntent getPendingIntentForClearingNotifications(final Context context, final int updateTargets,
        final ConversationIdSet conversationIdSet, final int requestCode) {
    final Intent intent = new Intent(context, NotificationReceiver.class);
    intent.setAction(ACTION_RESET_NOTIFICATIONS);
    intent.putExtra(UI_INTENT_EXTRA_NOTIFICATIONS_UPDATE, updateTargets);
    if (conversationIdSet != null) {
        intent.putExtra(UI_INTENT_EXTRA_CONVERSATION_ID_SET, conversationIdSet.getDelimitedString());
    }// w w w .j  av  a2  s .  c  om
    return PendingIntent.getBroadcast(context, requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}

From source file:com.android.messaging.ui.UIIntentsImpl.java

/**
 * Gets a PendingIntent associated with an Intent to start an Activity. All notifications
 * that starts an Activity must use this method to get a PendingIntent, which achieves two
 * goals://ww  w .  j  av  a 2 s.c  o m
 * 1. The target activities will be created, with any existing ones destroyed. This ensures
 *    we don't end up with multiple instances of ConversationListActivity, for example.
 * 2. The target activity, when launched, will have its backstack correctly constructed so
 *    back navigation will work correctly.
 */
private static PendingIntent getPendingIntentWithParentStack(final Context context, final Intent intent,
        final int requestCode) {
    final TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    // Adds the back stack for the Intent (plus the Intent itself)
    stackBuilder.addNextIntentWithParentStack(intent);
    final PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(requestCode,
            PendingIntent.FLAG_UPDATE_CURRENT);
    return resultPendingIntent;
}

From source file:com.amaze.carbonfilemanager.services.CopyService.java

/**
 * Displays a notification, sends intent and cancels progress if there were some failures
 * in copy progress//  w  ww. j  ava  2 s  . co m
 *
 * @param failedOps
 * @param move
 */
void generateNotification(ArrayList<HFile> failedOps, boolean move) {

    mNotifyManager.cancelAll();

    if (failedOps.size() == 0)
        return;

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(c);
    mBuilder.setContentTitle(c.getString(R.string.operationunsuccesful));
    mBuilder.setContentText(c.getString(R.string.copy_error).replace("%s",
            move ? c.getString(R.string.moved) : c.getString(R.string.copied)));
    mBuilder.setAutoCancel(true);

    progressHandler.setCancelled(true);

    Intent intent = new Intent(this, MainActivity.class);
    intent.putExtra(MainActivity.TAG_INTENT_FILTER_FAILED_OPS, failedOps);
    intent.putExtra("move", move);

    PendingIntent pIntent = PendingIntent.getActivity(this, 101, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    mBuilder.setContentIntent(pIntent);
    mBuilder.setSmallIcon(R.drawable.ic_content_copy_white_36dp);

    mNotifyManager.notify(741, mBuilder.build());

    intent = new Intent(MainActivity.TAG_INTENT_FILTER_GENERAL);
    intent.putExtra(MainActivity.TAG_INTENT_FILTER_FAILED_OPS, failedOps);
    intent.putExtra(TAG_COPY_MOVE, move);

    sendBroadcast(intent);
}

From source file:com.android.mail.utils.NotificationActionUtils.java

/**
 * Creates a {@link PendingIntent} for the specified Wear notification action.
 *//*from  www . j a va 2s . c o  m*/
private static PendingIntent getWearNotificationActionPendingIntent(final Context context,
        final Account account, final Conversation conversation, final Message message, final Folder folder,
        final Intent notificationIntent, final NotificationActionType action, final int notificationId,
        final long when) {
    final Uri messageUri = message.uri;

    final NotificationAction notificationAction = new NotificationAction(action, account, conversation, message,
            folder, conversation.id, message.serverId, message.id, when, NotificationAction.SOURCE_REMOTE,
            notificationId);

    switch (action) {
    case REPLY:
    case REPLY_ALL: {
        // Build a task stack that forces the conversation view on the stack before the
        // reply activity.
        final TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context);

        final Intent intent = createReplyIntent(context, account, messageUri,
                (action == NotificationActionType.REPLY_ALL));
        intent.setPackage(context.getPackageName());
        intent.setData(buildWearUri(conversation.uri));
        intent.putExtra(ComposeActivity.EXTRA_NOTIFICATION_FOLDER, folder);
        intent.putExtra(ComposeActivity.EXTRA_NOTIFICATION_CONVERSATION, conversation.uri);

        taskStackBuilder.addNextIntent(notificationIntent).addNextIntent(intent);

        return taskStackBuilder.getPendingIntent(notificationId, PendingIntent.FLAG_UPDATE_CURRENT);
    }
    case ARCHIVE_REMOVE_LABEL:
    case DELETE: {
        final String intentAction = (action == NotificationActionType.ARCHIVE_REMOVE_LABEL)
                ? NotificationActionIntentService.ACTION_ARCHIVE_REMOVE_LABEL
                : NotificationActionIntentService.ACTION_DELETE;

        final Intent intent = new Intent(intentAction);
        intent.setPackage(context.getPackageName());
        intent.setData(buildWearUri(conversation.uri));
        putNotificationActionExtra(intent, notificationAction);

        return PendingIntent.getService(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    }
    }

    throw new IllegalArgumentException("Invalid NotificationActionType");
}

From source file:com.ibm.mf.geofence.MFGeofencingManager.java

/**
 * Get a pending intent for the specified callback.
 * @param geofenceCallbackUuid the uuid of an internally mapped callback.
 * @return a <code>PendingIntent</code> instance.
 *//*from   w ww  .j  a  v  a2  s  .  c  o  m*/
private PendingIntent getPendingIntent(String geofenceCallbackUuid) {
    if (mPendingIntent == null) {
        Intent intent = new Intent(mContext, GeofenceTransitionsService.class);
        //intent.setPackage(context.getPackageName());
        ServiceConfig config = new ServiceConfig().fromGeofencingManager(this);
        config.populateFromSettings(mSettings);
        config.toIntent(intent);
        intent.putExtra(INTENT_ID, geofenceCallbackUuid);
        intent.setClass(mContext, GeofenceTransitionsService.class);
        mPendingIntent = PendingIntent.getService(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    }
    return mPendingIntent;
}

From source file:org.kaoriha.phonegap.plugins.releasenotification.Notifier.java

private void schedule(long after) {
    Intent intent = new Intent(ctx, Receiver.class);
    PendingIntent pi = PendingIntent.getBroadcast(ctx, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    AlarmManager am = (AlarmManager) ctx.getSystemService(Context.ALARM_SERVICE);
    am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + after, pi);
}

From source file:be.ugent.zeus.hydra.util.audiostream.MusicService.java

/**
 * Configures service as a foreground service. A foreground service is a service that's doing
 * something the user is actively aware of (such as playing music), and must appear to the user
 * as a notification. That's why we create the notification here.
 *//*from w  w w .  j a va  2 s  .c  o  m*/
void setUpAsForeground(String text) {
    PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0,
            new Intent(getApplicationContext(), Urgent.class), PendingIntent.FLAG_UPDATE_CURRENT);

    mNotification = new NotificationCompat.Builder(getApplicationContext()).setSmallIcon(R.drawable.urgent_icon)
            .setTicker(text).setContentTitle("Urgent.fm livestream").setContentText(text).setContentIntent(pi)
            .build();

    mNotification.flags |= Notification.FLAG_ONGOING_EVENT;
    startForeground(NOTIFICATION_ID, mNotification);
}

From source file:com.andrew.apolloMod.service.ApolloService.java

@SuppressLint({ "WorldWriteableFiles", "WorldReadableFiles" })
@Override//from w ww.ja v  a  2s . c o  m
public void onCreate() {
    super.onCreate();

    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    ComponentName rec = new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName());
    mAudioManager.registerMediaButtonEventReceiver(rec);
    Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
    mediaButtonIntent.setComponent(rec);
    PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, mediaButtonIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    if (Constants.isApi14Supported()) {
        mRemoteControlClient = new RemoteControlClient(mediaPendingIntent);
        mAudioManager.registerRemoteControlClient(mRemoteControlClient);

        int flags = RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS | RemoteControlClient.FLAG_KEY_MEDIA_NEXT
                | RemoteControlClient.FLAG_KEY_MEDIA_PLAY | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE
                | RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_STOP;
        mRemoteControlClient.setTransportControlFlags(flags);
    }

    mPreferences = getSharedPreferences(APOLLO_PREFERENCES, MODE_WORLD_READABLE | MODE_WORLD_WRITEABLE);
    mCardId = MusicUtils.getCardId(this);

    registerExternalStorageListener();

    // Needs to be done in this thread, since otherwise
    // ApplicationContext.getPowerManager() crashes.
    mPlayer = new MultiPlayer();
    mPlayer.setHandler(mMediaplayerHandler);

    reloadQueue();
    notifyChange(QUEUE_CHANGED);
    notifyChange(META_CHANGED);

    IntentFilter commandFilter = new IntentFilter();
    commandFilter.addAction(SERVICECMD);
    commandFilter.addAction(TOGGLEPAUSE_ACTION);
    commandFilter.addAction(PAUSE_ACTION);
    commandFilter.addAction(NEXT_ACTION);
    commandFilter.addAction(PREVIOUS_ACTION);
    commandFilter.addAction(CYCLEREPEAT_ACTION);
    commandFilter.addAction(TOGGLESHUFFLE_ACTION);
    registerReceiver(mIntentReceiver, commandFilter);

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this.getClass().getName());
    mWakeLock.setReferenceCounted(false);

    // If the service was idle, but got killed before it stopped itself, the
    // system will relaunch it. Make sure it gets stopped again in that
    // case.
    Message msg = mDelayedStopHandler.obtainMessage();
    mDelayedStopHandler.sendMessageDelayed(msg, IDLE_DELAY);
}

From source file:com.adkdevelopment.earthquakesurvival.ui.PagerActivity.java

private PendingIntent getGeofencePendingIntent() {
    Intent intent = new Intent(this, GeofenceService.class);
    // We use FLAG_UPDATE_CURRENT so that we get the same pending intent back when calling addgeoFences()
    return PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}

From source file:br.com.bioscada.apps.biotracks.widgets.TrackWidgetProvider.java

/**
 * Updates the stop button.//from  w  ww .  ja v a 2 s.com
 * 
 * @param context the context
 * @param remoteViews the remote views
 * @param isRecording true if recording
 */
private static void updateStopButton(Context context, RemoteViews remoteViews, boolean isRecording) {
    remoteViews.setImageViewResource(R.id.track_widget_stop_button,
            isRecording ? R.drawable.button_stop : R.drawable.ic_button_stop_disabled);
    remoteViews.setBoolean(R.id.track_widget_stop_button, "setEnabled", isRecording);
    if (isRecording) {
        Intent intent = new Intent(context, ControlRecordingService.class)
                .setAction(context.getString(R.string.track_action_end));
        PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        remoteViews.setOnClickPendingIntent(R.id.track_widget_stop_button, pendingIntent);
    }
}