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:butter.droid.base.torrent.TorrentService.java

public void startForeground() {
    if (Foreground.get().isForeground())
        return;//from  w  w  w  .j a  v  a 2  s .c  om
    if (mCurrentActivityClass == null)
        return;

    Intent notificationIntent = new Intent(this, mCurrentActivityClass);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    Intent stopIntent = new Intent();
    stopIntent.setAction(TorrentBroadcastReceiver.STOP);
    PendingIntent pendingStopIntent = PendingIntent.getBroadcast(this, TorrentBroadcastReceiver.REQUEST_CODE,
            stopIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Action stopAction = new NotificationCompat.Action.Builder(
            R.drawable.abc_ic_clear_mtrl_alpha, getString(R.string.stop), pendingStopIntent).build();

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_notif_logo)
            .setContentTitle(getString(R.string.app_name) + " - " + getString(R.string.running))
            .setContentText(getString(R.string.tap_to_resume)).setOngoing(true).setOnlyAlertOnce(true)
            .setPriority(Notification.PRIORITY_LOW).setContentIntent(pendingIntent).addAction(stopAction)
            .setCategory(NotificationCompat.CATEGORY_SERVICE);

    if (mStreamStatus != null && mIsReady) {
        String downloadSpeed;
        DecimalFormat df = new DecimalFormat("#############0.00");
        if (mStreamStatus.downloadSpeed / 1024 < 1000) {
            downloadSpeed = df.format(mStreamStatus.downloadSpeed / 1024) + " KB/s";
        } else {
            downloadSpeed = df.format(mStreamStatus.downloadSpeed / (1024 * 1024)) + " MB/s";
        }
        String progress = df.format(mStreamStatus.progress);
        builder.setContentText(progress + "%, " + downloadSpeed);
    }

    Notification notification = builder.build();

    NotificationManager notifManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    notifManager.notify(NOTIFICATION_ID, notification);
    startForeground(NOTIFICATION_ID, notification);

    if (mUpdateTimer == null) {
        mUpdateTimer = new Timer();
        mUpdateTimer.scheduleAtFixedRate(new UpdateTask(), 5000, 5000);
    }
}

From source file:com.android.example.leanback.fastlane.RecommendationsService.java

private PendingIntent buildPendingIntent(Video video) {
    Intent detailsIntent = new Intent(this, PlayerActivity.class);
    detailsIntent.putExtra(Video.INTENT_EXTRA_VIDEO, video);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(VideoDetailsActivity.class);
    stackBuilder.addNextIntent(detailsIntent);
    // Ensure a unique PendingIntents, otherwise all recommendations end up with the same
    // PendingIntent
    detailsIntent.setAction(Long.toString(video.getId()));

    PendingIntent intent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    return intent;
}

From source file:de.electricdynamite.pasty.GCMIntentService.java

@SuppressLint("NewApi")
@Override/* www . j  a  v  a  2 s. c om*/
protected void onMessage(Context context, Intent intent) {
    if (prefs == null)
        this.prefs = new PastyPreferencesProvider(context);
    final Bundle extras = intent.getExtras();
    if (extras == null) {
        Log.i(TAG, "onMessage(): Empty intent received");
        return;
    }
    final String mItemId = extras.getString("itemId");
    final String mItemStr = extras.getString("item");
    final int mEventId = Integer.parseInt(extras.getString("eventId"));
    if (mItemId == null || mItemStr == null || mItemId == "" || mItemStr == "") {
        Log.i(TAG, "onMessage(): Invalid intent received");
        return;
    }
    if (LOCAL_LOG)
        Log.v(TAG, "onMessage(): Received message for event: " + mEventId);
    switch (mEventId) {
    case EVENT_ITEM_ADDED:
        final String lastItemId = prefs.getLastItem();
        if (mItemId.equals(lastItemId))
            return;
        if (client == null) {
            client = new PastyClient(prefs.getRESTBaseURL(), true);
            client.setUsername(prefs.getUsername());
            client.setPassword(prefs.getPassword());
        }

        final ClipboardItem mItem = new ClipboardItem(mItemId, mItemStr);
        final Boolean mPush = prefs.getPush();
        final Boolean mCopyToClipboard = prefs.getPushCopyToClipboard();
        final Boolean mNotify = prefs.getPushNotify();
        if (mPush == true) {
            if (mCopyToClipboard == true) {
                if (mItem.getText() != "") {
                    Intent resultIntent = new Intent(this, CopyService.class);
                    resultIntent.putExtra("de.electricdynamite.pasty.itemId", mItem.getId());
                    resultIntent.putExtra("de.electricdynamite.pasty.item", mItem.getText());
                    resultIntent.putExtra("de.electricdynamite.pasty.notify", mNotify);
                    startService(resultIntent);
                    resultIntent = null;
                }
            } else {
                if (mNotify == true) {
                    String contentText = String.format(getString(R.string.notification_event_add_text),
                            mItem.getText());
                    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
                            .setSmallIcon(R.drawable.ic_stat_pasty)
                            .setContentTitle(getString(R.string.notification_event_add_title))
                            .setContentText(contentText).setAutoCancel(Boolean.TRUE);
                    // Creates an explicit intent for an Activity in your app
                    Intent resultIntent = new Intent(this, CopyService.class);
                    resultIntent.putExtra("de.electricdynamite.pasty.itemId", mItem.getId());
                    resultIntent.putExtra("de.electricdynamite.pasty.item", mItem.getText());
                    resultIntent.putExtra("de.electricdynamite.pasty.notify", mNotify);
                    PendingIntent resultPendingIntent = PendingIntent.getService(context, 0, resultIntent,
                            PendingIntent.FLAG_UPDATE_CURRENT);
                    mBuilder.setContentIntent(resultPendingIntent);
                    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
                            Context.NOTIFICATION_SERVICE);
                    // mId allows you to update the notification later on.
                    mNotificationManager.notify(PastySharedStatics.NOTIFICATION_ID, mBuilder.build());
                }
            }
            JSONArray clipboard = null;
            try {
                clipboard = client.getClipboard();
                cacheClipboard(clipboard);
            } catch (PastyException e) {
                if (LOCAL_LOG)
                    Log.v(TAG, "Could not get clipboard: " + e.getMessage());
            }

        }
        break;
    default:
        Log.i(TAG, "onMessage(): Unsupported event: " + mEventId);
        break;
    }
    /* TODO Make ClipboardFragment react to changes from GCMIntentService */
}

From source file:com.bufarini.reminders.AlarmReceiver.java

private void showNotification(Context context, Intent intent) {
    Intent snoozeIntent = new Intent(context, NotificationActivity.class);
    snoozeIntent.putExtras(intent.getExtras());
    snoozeIntent.putExtra("notificaton action", "snooze");
    PendingIntent snoozePendingIntent = PendingIntent.getActivity(context, 0, snoozeIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    Intent doneIntent = new Intent(context, NotificationActivity.class);
    doneIntent.putExtras(intent.getExtras());
    doneIntent.putExtra("notificaton action", "done");
    doneIntent.putExtra("task", intent.getSerializableExtra("task"));
    PendingIntent donePendingIntent = PendingIntent.getActivity(context, 1, doneIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    Intent resultIntent = new Intent(context, Reminders.class);
    resultIntent.putExtra("action", "view task");
    resultIntent.putExtra("task", intent.getSerializableExtra("task"));
    resultIntent.setFlags(//w  ww  . j a v  a2 s . c  o  m
            Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setAutoCancel(true)
            .setSmallIcon(R.drawable.ic_action_alarms)
            .setContentTitle(context.getResources().getString(R.string.alarmPopupTitle1))
            .setContentIntent(resultPendingIntent)
            .addAction(R.drawable.ic_action_alarms, "Snooze", snoozePendingIntent)
            .addAction(R.drawable.ic_action_done, "Done", donePendingIntent)
            .setContentText(intent.getExtras().getString(NotificationUtils.TITLE));

    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    int notificationId = NotificationUtils.getNotificationId(intent.getExtras().getLong(NotificationUtils.ID));
    notificationManager.notify(notificationId, builder.build());
}

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

public void stop() {
    AlarmManager am = (AlarmManager) ctx.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(ctx, Receiver.class);
    PendingIntent pi = PendingIntent.getBroadcast(ctx, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    am.cancel(pi);/*from  w  w w.  ja  v a2  s  .  com*/
}

From source file:com.moto.miletus.application.ble.neardevice.NearDeviceNotification.java

/**
 * notification/*from  w  w  w.j av  a 2 s .  c o  m*/
 *
 * @param room  String
 * @param light ParameterValue
 * @param temp  ParameterValue
 */
private void notification(final String room, final ParameterValue light, final ParameterValue temp) {
    String msg;
    if (room == null) {
        systemService.cancelAll();
        return;
    } else if (light != null && temp != null) {
        msg = "Welcome to: " + room + Strings.NEW_LINE + "Light: " + light.getValue() + Strings.LUX
                + Strings.NEW_LINE;

        try {
            String tempRound = Precision.round(Float.parseFloat(temp.getValue()), 1) + "";
            msg = msg + "Temp: " + tempRound + Strings.CELSIUS + Strings.NEW_LINE;
        } catch (NumberFormatException ex) {
            Log.e(TAG, ex.toString());
        }
    } else {
        msg = "Welcome to: " + room + Strings.NEW_LINE;
    }

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.miletus).setContentTitle("Room Status")
            .setPriority(NotificationCompat.PRIORITY_MAX).setContentText(msg);

    Intent resultIntent = new Intent(context, MainActivity.class);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);

    systemService.notify(9812, mBuilder.build());

    Log.i(TAG, msg);
}

From source file:com.adam.aslfms.service.ScrobblingService.java

@Override
public int onStartCommand(Intent i, int flags, int startId) {
    handleCommand(i, startId);//  w w  w.j  av a  2 s. co m

    String ar = "";
    String tr = "";
    String api = "";
    if (mCurrentTrack != null) {
        ar = mCurrentTrack.getArtist();
        tr = mCurrentTrack.getTrack();
        api = mCurrentTrack.getMusicAPI().readAPIname();
    }

    Intent targetIntent = new Intent(mCtx, SettingsActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(mCtx, 0, targetIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(mCtx).setContentTitle(ar)
            .setSmallIcon(R.mipmap.ic_notify).setContentText(tr + " : " + api).setContentIntent(contentIntent);

    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB_MR2) {
        builder.setLargeIcon(BitmapFactory.decodeResource(mCtx.getResources(), R.mipmap.ic_launcher));
    }

    this.startForeground(14619, builder.build());

    if (!settings.isNotifyEnabled(Util.checkPower(mCtx))) {
        Intent iNoti = new Intent(mCtx, ForegroundHide.class);
        this.startService(iNoti);
    }
    return Service.START_STICKY;
}

From source file:luan.com.flippit.GcmIntentService.java

private void extraDialog(String msg, String extraFilename, String extraType) {
    Log.i(MyActivity.TAG, getClass().getName() + ": " + "Extra notification.");

    String url = msg;// www .  ja  v a2 s. co m
    Intent intentWeb = new Intent(Intent.ACTION_VIEW);
    intentWeb.setData(Uri.parse(url));
    PendingIntent pendingWeb = PendingIntent.getActivity(mContext, 0, intentWeb,
            PendingIntent.FLAG_UPDATE_CURRENT);

    Intent intentCopy = new Intent(mContext, CopyService.class);
    intentCopy.putExtra("msg", msg);
    PendingIntent pendingCopy = PendingIntent.getService(mContext, 0, intentCopy,
            PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder mBuilder = GeneralUtilities.createNotificationBuilder(mContext);
    mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setTicker("Rich message")
            .addAction(R.drawable.send_white, "Open", pendingWeb)
            .addAction(R.drawable.copy_white, "Copy", pendingCopy).setContentText("Rich message");
    mNotificationManager.cancel(1);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
    UpdateHistory updateHistory = new UpdateHistory();
    updateHistory.updateHistory(mContext);
}

From source file:com.classiqo.nativeandroid_32bitz.MusicService.java

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

    mMusicProvider = new MusicProvider();
    mMusicProvider.retrieveMediaAsync(null);
    mPackageValidator = new PackageValidator(this);

    QueueManager queueManager = new QueueManager(mMusicProvider, getResources(),
            new QueueManager.MetadataUpdateListener() {
                @Override/* w w w  . j a va 2  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);

    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, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    mSession.setSessionActivity(pi);

    mSessionExtras = new Bundle();
    //        CarHelper.setSlotReservationFlags(mSessionExtras, true, true, true);
    //        WearHelper.setSlotReservationFlags(mSessionExtras, true, true);
    //        SearHelper.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);
    }

    //        if (!TvHelper.isTvUiMode(this)) {
    //            mCastSessionManager = CastContext.getSharedInstance(this).getSessionManager();
    //            mCastSessionManagerListener = new CastSessionManagerListener();
    //            mCastSessionManager.addSessionManagerListener(mCastSessionManagerListener, CastSession.class);
    //        }

    mMediaRouter = MediaRouter.getInstance(getApplicationContext());

    //        registerCarConnectionReceiver();
}

From source file:de.grobox.blitzmail.AsyncMailTask.java

@Override
protected void onPostExecute(Boolean result) {
    String msg = "";

    // set progress notification to finished
    activity.mBuilder.setProgress(0, 0, false);
    activity.mBuilder.setOngoing(false);

    // set dialog to auto close when clicked
    activity.mBuilder.setAutoCancel(true);

    if (result) {
        // Everything went fine, so delete mail from local storage
        MailStorage.deleteMail(activity, mail.optString("id"));

        // check to see if there should be a success notification
        if (!PreferenceManager.getDefaultSharedPreferences(activity).getBoolean("pref_success_notification",
                true)) {/*from   w  ww. j  a v  a2  s.  c o  m*/
            // don't show success notification
            activity.mNotifyManager.cancel(0);
            return;
        }
        // show success notification
        activity.mBuilder.setSmallIcon(R.drawable.ic_launcher);
        activity.mBuilder.setContentTitle(activity.getString(R.string.sent_mail));
        activity.notifyIntent.putExtra("ContentTitle", activity.getString(R.string.sent_mail));
        msg = mail.optString("subject");
    } else {
        activity.mBuilder.setContentTitle(
                activity.getString(R.string.app_name) + " - " + activity.getString(R.string.error));
        activity.notifyIntent.putExtra("ContentTitle", activity.getString(R.string.error));
        activity.mBuilder.setSmallIcon(android.R.drawable.ic_dialog_alert);

        Log.d("AsyncMailTask", e.getClass().getCanonicalName());

        if (e.getClass().getCanonicalName().equals("javax.mail.AuthenticationFailedException")) {
            msg = activity.getString(R.string.error_auth_failed);
        } else if (e.getClass().getCanonicalName().equals("javax.mail.MessagingException")
                && e.getCause() != null
                && e.getCause().getClass().getCanonicalName().equals("javax.net.ssl.SSLException")
                && e.getCause().getCause().getClass().getCanonicalName()
                        .equals("java.security.cert.CertificateException")) {
            // TODO use MemorizingTrustManager instead, issue #1
            msg = activity.getString(R.string.error_sslcert_invalid);
        } else {
            msg = activity.getString(R.string.error_smtp) + '\n' + e.getMessage();
        }

        // get and show the cause for the exception if it exists
        if (e.getCause() != null) {
            Throwable ecause = e.getCause();
            Log.d("AsyncMailTask", ecause.getClass().getCanonicalName());
            msg += "\nCause: " + ecause.getMessage();
        }
    }

    // Update the notification
    activity.mBuilder.setContentText(msg);
    activity.notifyIntent.putExtra("ContentText", msg);
    activity.mBuilder.setContentIntent(
            PendingIntent.getActivity(activity, 0, activity.notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT));
    activity.mNotifyManager.notify(0, activity.mBuilder.build());
}