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:ca.zadrox.dota2esportticker.service.UpdateMatchService.java

private void scheduleAutoUpdates() {

    if (!PrefUtils.shouldAutoUpdate(this)) {
        return;/*w  w  w  .j a va 2 s .  c  om*/
    }

    final long currentTime = TimeUtils.getUTCTime();

    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);

    final long matchUpdateTime = currentTime + (60000 * 60 * 12);
    final long resultUpdateTime = currentTime + (60000 * 60);

    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);
    am.cancel(uri);

    am.setInexactRepeating(AlarmManager.RTC, matchUpdateTime, AlarmManager.INTERVAL_HALF_DAY, umi);

    am.setInexactRepeating(AlarmManager.RTC, resultUpdateTime, AlarmManager.INTERVAL_HOUR, uri);
}

From source file:com.github.notizklotz.derbunddownloader.download.IssueDownloadService.java

private void notifyUser(CharSequence contentTitle, CharSequence contentText, int icon) {
    Notification.Builder mBuilder = new Notification.Builder(getApplicationContext()).setSmallIcon(icon)
            .setContentTitle(contentTitle).setContentText(contentText).setTicker(contentTitle)
            .setAutoCancel(true);/*from   w ww .  j  a  va  2s.  c o  m*/

    //http://developer.android.com/guide/topics/ui/notifiers/notifications.html
    // The stack builder object will contain an artificial back stack for thestarted Activity.
    // This ensures that navigating backward from the Activity leads out of your application to the Home screen.
    mBuilder.setContentIntent(android.support.v4.app.TaskStackBuilder.create(getApplicationContext())
            .addParentStack(DownloadedIssuesActivity_.class)
            .addNextIntent(new Intent(getApplicationContext(), DownloadedIssuesActivity_.class))
            .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT));

    NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    //noinspection deprecation
    mNotifyMgr.notify(1, mBuilder.getNotification());
}

From source file:com.vendsy.bartsy.venue.BartsyApplication.java

private void generateNotification(final String title, final String body, final int count) {
    mHandler.post(new Runnable() {
        public void run() {
            // Get app icon bitmap and scale to fit in notification
            Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
            largeIcon = Bitmap.createScaledBitmap(largeIcon, NOTIFICATION_IMAGE_SIZE, NOTIFICATION_IMAGE_SIZE,
                    true);/*from w w  w  . ja  v  a  2 s.  c  o m*/

            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext())
                    .setLargeIcon(largeIcon).setSmallIcon(R.drawable.ic_launcher).setContentTitle(title)
                    .setContentText(body);

            // Creates an explicit intent for an Activity in your app
            Intent resultIntent = new Intent(getApplicationContext(), MainActivity.class);

            // The stack builder object will contain an artificial back stack for the
            // started Activity.
            // This ensures that navigating backward from the Activity leads out of
            // your application to the Home screen.
            TaskStackBuilder stackBuilder = TaskStackBuilder.create(getApplicationContext());
            // Adds the back stack for the Intent (but not the Intent itself)
            stackBuilder.addParentStack(MainActivity.class);
            // Adds the Intent that starts the Activity to the top of the stack
            stackBuilder.addNextIntent(resultIntent);
            PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            mBuilder.setContentIntent(resultPendingIntent);
            mBuilder.setNumber(count);
            NotificationManager mNotificationManager = (NotificationManager) getSystemService(
                    Context.NOTIFICATION_SERVICE);

            // Play default notification sound
            mBuilder.setDefaults(Notification.DEFAULT_SOUND);
            // mId allows you to update the notification later on.
            mNotificationManager.notify(0, mBuilder.build());
        }
    });
}

From source file:com.nextgis.firereporter.GetFiresService.java

protected void Prepare() {
    mLocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    mnCurrentExec = 0;//from   ww  w . ja v  a 2s .  c  om
    mmoFires = new HashMap<Long, FireItem>();

    mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    nUserCount = 0;
    nNasaCount = 0;
    nScanexCount = 0;
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(new Intent(this, MainActivity.class));
    //stackBuilder.addNextIntent(new Intent(this, ScanexNotificationsActivity.class));
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_fire_small)
            .setContentTitle(getString(R.string.stNewFireNotifications));
    mBuilder.setContentIntent(resultPendingIntent);

    Intent delIntent = new Intent(this, GetFiresService.class);
    delIntent.putExtra(COMMAND, SERVICE_NOTIFY_DISMISSED);
    PendingIntent deletePendingIntent = PendingIntent.getService(this, 0, delIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setDeleteIntent(deletePendingIntent);

    mInboxStyle = new NotificationCompat.InboxStyle();
    mInboxStyle.setBigContentTitle(getString(R.string.stNewFireNotificationDetailes));

    LoadScanexData();

    mSanextCookieTime = new Time();
    mSanextCookieTime.setToNow();
    msScanexLoginCookie = new String("not_set");

    mFillDataHandler = new Handler() {
        public void handleMessage(Message msg) {

            mnCurrentExec--;

            Bundle resultData = msg.getData();
            boolean bHaveErr = resultData.getBoolean(ERROR);
            if (bHaveErr) {
                SendError(resultData.getString(ERR_MSG));
            } else {
                int nType = resultData.getInt(SOURCE);
                String sData = resultData.getString(JSON);
                switch (nType) {
                case 3:
                    FillScanexData(nType, sData);
                    break;
                case 4:
                    msScanexLoginCookie = sData;
                    mSanextCookieTime.setToNow();
                    GetScanexData(false);
                    break;
                default:
                    FillData(nType, sData);
                    break;
                }
            }
            GetDataStoped();
        };
    };
}

From source file:at.diamonddogs.util.CacheManager.java

private PendingIntent getAlarmIntent(Context context) {
    Intent intent = new Intent(context.getApplicationContext(), CacheAlarmReceiver.class);
    intent.setAction(ACTION_INTENT_SCHEDULE_CACHE);
    PendingIntent pi = PendingIntent.getBroadcast(context.getApplicationContext(), 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    return pi;/* w  ww.  ja  va 2s .c  o  m*/
}

From source file:air.com.snagfilms.cast.chromecast.notifications.VideoCastNotificationService.java

private RemoteViews build(MediaInfo info, Bitmap bitmap, boolean isPlaying, Class<?> targetActivity)
        throws CastException, TransientNetworkDisconnectionException, NoConnectionException {
    Bundle mediaWrapper = Utils.fromMediaInfo(mCastManager.getRemoteMediaInformation());
    Intent contentIntent = null;/* w w w .  j  a v a  2s  . co  m*/
    if (null == mTargetActivity) {
        mTargetActivity = VideoPlayerActivity.class;
    }
    contentIntent = new Intent(this, mTargetActivity);

    contentIntent.putExtra("media", mediaWrapper);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

    stackBuilder.addParentStack(mTargetActivity);

    stackBuilder.addNextIntent(contentIntent);
    if (stackBuilder.getIntentCount() > 1) {
        stackBuilder.editIntentAt(1).putExtra("media", mediaWrapper);
    }

    // Gets a PendingIntent containing the entire back stack
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(NOTIFICATION_ID,
            PendingIntent.FLAG_UPDATE_CURRENT);

    MediaMetadata mm = info.getMetadata();

    RemoteViews rv = new RemoteViews(getPackageName(), R.layout.custom_notification);
    if (mIsIcsOrAbove) {
        addPendingIntents(rv, isPlaying, info);
    }
    if (null != bitmap) {
        rv.setImageViewBitmap(R.id.iconView, bitmap);
    }
    rv.setTextViewText(R.id.titleView, mm.getString(MediaMetadata.KEY_TITLE));
    String castingTo = getResources().getString(R.string.casting_to_device, mCastManager.getDeviceName());
    rv.setTextViewText(R.id.subTitleView, castingTo);
    mNotification = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_stat_action_notification)
            .setContentIntent(resultPendingIntent).setContent(rv).setAutoCancel(false).setOngoing(true).build();

    // to get around a bug in GB version, we add the following line
    // see https://code.google.com/p/android/issues/detail?id=30495
    mNotification.contentView = rv;

    return rv;
}

From source file:com.android.screenspeak.ScreenSpeakUpdateHelper.java

private Notification buildGestureChangeNotification(Intent clickIntent) {
    final PendingIntent pendingIntent = PendingIntent.getActivity(mService, 0, clickIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    final String ticker = mService.getString(R.string.notification_title_screenspeak_gestures_changed);
    final String contentTitle = mService.getString(R.string.notification_title_screenspeak_gestures_changed);
    final String contentText = mService.getString(R.string.notification_message_screenspeak_gestures_changed);
    final Notification notification = new NotificationCompat.Builder(mService)
            .setSmallIcon(R.drawable.ic_stat_info).setTicker(ticker).setContentTitle(contentTitle)
            .setContentText(contentText).setContentIntent(pendingIntent).setAutoCancel(false).setWhen(0)
            .build();//from w  w w  .  ja v a  2  s. c  o m

    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.flags |= Notification.FLAG_ONGOING_EVENT;
    return notification;
}

From source file:ota.otaupdates.MainActivity.java

private void create_notification(int id, String title, String content) {
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon((android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP
                    ? R.drawable.app_icon_notification
                    : R.drawable.app_icon))
            .setContentTitle(title).setContentText(content);

    Intent resultIntent = new Intent(this, MainActivity.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(id, mBuilder.build());
}

From source file:com.ntsync.android.sync.activities.PaymentVerificationService.java

private static void sendNotification(Context context, Account account, int msg,
        Class<? extends Activity> activityClass, boolean showMsg) {
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    Intent viewIntent = new Intent(context, activityClass);
    if (ShopActivity.class.equals(activityClass)) {
        // Vollstndige Meldung in der View anzeigen
        CharSequence msgText = context.getText(msg);
        if (showMsg) {
            // Show Full Message in ShopActivity
            viewIntent.putExtra(ShopActivity.PARM_MSG, String
                    .format(context.getText(R.string.shop_activity_delayedverif_failed).toString(), msgText));
        }//from  w w  w  . j a v a2s .  c  o  m
        viewIntent.putExtra(ShopActivity.PARM_ACCOUNT_NAME, account.name);
    }

    // Adds the back stack
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(activityClass);
    stackBuilder.addNextIntent(viewIntent);

    // Photo sync possible.
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setSmallIcon(Constants.NOTIF_ICON).setContentTitle(context.getText(msg))
            .setContentText(account.name).setAutoCancel(true).setOnlyAlertOnce(true)
            .setContentIntent(stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT));
    notificationManager.notify(Constants.NOTIF_PAYMENT_VERIFICATIONRESULT, builder.build());
}

From source file:com.battlelancer.seriesguide.billing.BillingActivity.java

/**
 * Displays a notification that the subscription has expired. Its action opens {@link
 * BillingActivity}./*from ww w. j a v  a 2s. com*/
 */
public static void onExpiredNotification(Context context) {
    NotificationCompat.Builder nb = new NotificationCompat.Builder(context);

    // set required attributes
    nb.setSmallIcon(R.drawable.ic_notification);
    nb.setContentTitle(context.getString(R.string.subscription_expired));
    nb.setContentText(context.getString(R.string.subscription_expired_details));

    // set additional attributes
    nb.setDefaults(Notification.DEFAULT_LIGHTS);
    nb.setAutoCancel(true);
    nb.setTicker(context.getString(R.string.subscription_expired_details));
    nb.setPriority(NotificationCompat.PRIORITY_DEFAULT);

    // build task stack
    Intent notificationIntent = new Intent(context, BillingActivity.class);
    PendingIntent contentIntent = TaskStackBuilder.create(context)
            .addNextIntent(new Intent(context, ShowsActivity.class))
            .addNextIntent(new Intent(context, SeriesGuidePreferences.class)).addNextIntent(notificationIntent)
            .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    nb.setContentIntent(contentIntent);

    // build the notification
    Notification notification = nb.build();

    // show the notification
    final NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(R.string.subscription_expired, notification);
}