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.meiste.greg.ptw.WidgetProvider.java

private PendingIntent getAlarmIntent(final Context context) {
    final Intent intent = new Intent(context, WidgetProvider.class);
    return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}

From source file:com.apps.howard.vicissitude.services.NotificationService.java

private void buildNotification(String message, String sender) {
    String newNotificationMessage = maybeSetNotificationMessage(sender);

    newNotificationMessage += message + System.getProperty("line.separator");

    NotificationCompat.Builder mBuilder = getNotificationBuilder(message, sender);

    // Creates an explicit intent for an Activity in your app
    Notification mNotification;/*from  ww w  .  ja v  a  2  s.  c o m*/

    Intent resultIntent = new Intent(this, NotificationService.class);
    resultIntent.setAction(sender);

    PendingIntent resultPendingIntent = PendingIntent.getService(this, 0, resultIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    mBuilder.setContentIntent(resultPendingIntent);
    mBuilder.setDeleteIntent(resultPendingIntent);

    mNotification = mBuilder.build();
    mNotification.flags |= Notification.FLAG_INSISTENT;

    this.lastNotificationMessage.put(sender, newNotificationMessage);

    maybeOverrideVolumeBeforeNotify();

    notificationManager.notify(sender, 1, mNotification);
    vibrator.vibrate(vibrationPattern, 0);
}

From source file:com.cardio3g.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    Fabric.with(this, new Crashlytics());
    setContentView(R.layout.activity_main);
    mDownloadViewGroup = (RelativeLayout) findViewById(R.id.downloadViewGroup);
    mDownloadProgressBar = (ProgressBar) findViewById(R.id.downloadProgressBar);
    mProgressPercentTextView = (TextView) findViewById(R.id.downloadProgressPercentTextView);
    mainLayout = (RelativeLayout) findViewById(R.id.mainLayout);
    mDownloaderClientStub = DownloaderClientMarshaller.CreateStub(this, DownloaderService.class);
    if (!expansionFilesDelivered()) {

        try {/*from www  . j  a v a 2  s .c  o  m*/
            Intent launchIntent = MainActivity.this.getIntent();
            Intent intentToLaunchThisActivityFromNotification = new Intent(MainActivity.this,
                    MainActivity.this.getClass());
            intentToLaunchThisActivityFromNotification
                    .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
            intentToLaunchThisActivityFromNotification.setAction(launchIntent.getAction());

            if (launchIntent.getCategories() != null) {
                for (String category : launchIntent.getCategories()) {
                    intentToLaunchThisActivityFromNotification.addCategory(category);
                }
            }

            // Build PendingIntent used to open this activity from
            // Notification
            PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, 0,
                    intentToLaunchThisActivityFromNotification, PendingIntent.FLAG_UPDATE_CURRENT);
            // Request to start the download
            int startResult = DownloaderClientMarshaller.startDownloadServiceIfRequired(this, pendingIntent,
                    DownloaderService.class);

            if (startResult != DownloaderClientMarshaller.NO_DOWNLOAD_REQUIRED) {
                // The DownloaderService has started downloading the files, show progress
                initializeDownloadUI();
                return;
            } // otherwise, download not needed so we fall through to the app
        } catch (PackageManager.NameNotFoundException e) {
            Log.e("EXPANSION ERROR", "Cannot find package!", e);
        }
    } else {
        validateXAPKZipFiles();
    }

    btnBuiltIn = (Button) findViewById(R.id.button_builtin);
    btnMuscleIsolation = (Button) findViewById(R.id.button_muscle);
    btnCustomProgram = (Button) findViewById(R.id.button_custom);
    btnSportsTraining = (Button) findViewById(R.id.button_sports);
    btnhealthyLiving = (Button) findViewById(R.id.button_healthy);
    btnPersonalTrainer = (Button) findViewById(R.id.button_personal);
    btnVideos = (Button) findViewById(R.id.button_exercise_videos);
    btnCardio = (Button) findViewById(R.id.button_visit);
    btnImages = (Button) findViewById(R.id.button_exercise_photos);
    frameLayout = (FrameLayout) findViewById(R.id.frame);
    videoView = (VideoView) findViewById(R.id.video_view);
    btnBuiltIn.setOnClickListener(this);
    btnMuscleIsolation.setOnClickListener(this);
    btnCustomProgram.setOnClickListener(this);
    btnSportsTraining.setOnClickListener(this);
    btnhealthyLiving.setOnClickListener(this);
    btnPersonalTrainer.setOnClickListener(this);
    btnVideos.setOnClickListener(this);
    btnCardio.setOnClickListener(this);
    btnImages.setOnClickListener(this);

    mediaController = new MediaController(MainActivity.this);
    checkPermission();
}

From source file:com.piggate.sdk.Piggate.java

public void postNotification(String title, String msg, Class myClass, int resource, Bundle extras,
        Boolean force) {/*  www . j  a  va2 s  .c om*/
    if (!getApplicationContext().getPackageName()
            .equalsIgnoreCase(((ActivityManager) getApplicationContext()
                    .getSystemService(getApplicationContext().ACTIVITY_SERVICE)).getRunningAppProcesses()
                            .get(0).processName)
            || force) {

        Intent notifyIntent = new Intent(_context, myClass);
        if (extras != null)
            notifyIntent.putExtras(extras);
        notifyIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

        PendingIntent pendingIntent = PendingIntent.getActivities(_context, 0, new Intent[] { notifyIntent },
                PendingIntent.FLAG_UPDATE_CURRENT);
        Notification notification = new Notification.Builder(_context).setSmallIcon(resource)
                .setContentTitle(title).setContentText(msg).setAutoCancel(true).setContentIntent(pendingIntent)
                .build();
        notification.defaults |= Notification.DEFAULT_SOUND;
        notification.defaults |= Notification.DEFAULT_LIGHTS;
        notificationManager.notify(123, notification);
    }
}

From source file:com.QuarkLabs.BTCeClient.UpdateWidgetsTask.java

@Override
protected void onPostExecute(JSONObject jsonObject) {
    if (jsonObject != null) {
        try {//from w w  w.  j  a  v  a 2s. com
            Context context = mContext.get();
            if (context == null) {
                return;
            }
            AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
            for (int x : mMap.keySet()) {
                RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget_layout);
                double price = jsonObject.getJSONObject(mMap.get(x).replace("/", "_").toLowerCase(Locale.US))
                        .getDouble("last");
                String priceString;
                if (price > 1) {
                    priceString = (new DecimalFormat("#.##")).format(price);
                } else {
                    priceString = String.valueOf(price);
                }
                views.setTextViewText(R.id.widgetCurrencyValue, priceString);
                views.setTextViewText(R.id.widgetPair, mMap.get(x));
                String color = jsonObject.getJSONObject(mMap.get(x).replace("/", "_").toLowerCase(Locale.US))
                        .getString("color");
                int colorValue = color.equals("green") ? Color.GREEN : Color.RED;
                views.setTextColor(R.id.widgetCurrencyValue, colorValue);
                Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
                Bundle bundle = new Bundle();
                bundle.putIntArray(AppWidgetManager.EXTRA_APPWIDGET_IDS,
                        appWidgetManager.getAppWidgetIds(new ComponentName(context, WidgetProvider.class)));
                intent.putExtras(bundle);
                PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent,
                        PendingIntent.FLAG_UPDATE_CURRENT);
                views.setOnClickPendingIntent(R.id.widgetContainer, pi);
                SimpleDateFormat df = new SimpleDateFormat("EEE HH:mm", Locale.US);
                Calendar calendar = Calendar.getInstance();
                views.setTextViewText(R.id.widgetDate, df.format(calendar.getTime()));
                appWidgetManager.updateAppWidget(x, views);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}

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

public void ScheduleNextUpdate(Context context, long nMinTimeBetweenSend, boolean bEnergyEconomy) {
    if (context == null)
        return;/*from w w  w  .j av a2s .  co m*/

    Intent intent = new Intent(ReporterService.ACTION_START);
    PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // The update frequency should often be user configurable.  This is not.

    long currentTimeMillis = System.currentTimeMillis();
    long nextUpdateTimeMillis = currentTimeMillis + nMinTimeBetweenSend;
    Time nextUpdateTime = new Time();
    nextUpdateTime.set(nextUpdateTimeMillis);

    AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    if (bEnergyEconomy)
        alarmManager.set(AlarmManager.RTC, nextUpdateTimeMillis, pendingIntent);
    else
        alarmManager.set(AlarmManager.RTC_WAKEUP, nextUpdateTimeMillis, pendingIntent);
}

From source file:com.battlelancer.seriesguide.appwidget.ListWidgetProvider.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public static RemoteViews buildRemoteViews(Context context, AppWidgetManager appWidgetManager,
        int appWidgetId) {
    // setup intent pointing to RemoteViewsService providing the views for the collection
    Intent intent = new Intent(context, ListWidgetService.class);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    // When intents are compared, the extras are ignored, so we need to
    // embed the extras into the data so that the extras will not be
    // ignored.//w  w w. j  a v a  2s. c  om
    intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));

    // determine layout (current size) and theme (user pref)
    final boolean isCompactLayout = isCompactLayout(appWidgetManager, appWidgetId);
    final boolean isLightTheme = WidgetSettings.isLightTheme(context, appWidgetId);
    int layoutResId;
    if (isLightTheme) {
        layoutResId = isCompactLayout ? R.layout.appwidget_v11_light_compact : R.layout.appwidget_v11_light;
    } else {
        layoutResId = isCompactLayout ? R.layout.appwidget_v11_compact : R.layout.appwidget_v11;
    }

    // build widget views
    RemoteViews rv = new RemoteViews(context.getPackageName(), layoutResId);
    rv.setRemoteAdapter(R.id.list_view, intent);
    // The empty view is displayed when the collection has no items. It
    // should be a sibling of the collection view.
    rv.setEmptyView(R.id.list_view, R.id.empty_view);

    // set the background color
    int bgColor = WidgetSettings.getWidgetBackgroundColor(context, appWidgetId, isLightTheme);
    rv.setInt(R.id.container, "setBackgroundColor", bgColor);

    // determine type specific values
    final int widgetType = WidgetSettings.getWidgetListType(context, appWidgetId);
    int showsTabIndex;
    int titleResId;
    int emptyResId;
    if (widgetType == WidgetSettings.Type.UPCOMING) {
        // upcoming
        showsTabIndex = ShowsActivity.InitBundle.INDEX_TAB_UPCOMING;
        titleResId = R.string.upcoming;
        emptyResId = R.string.noupcoming;
    } else if (widgetType == WidgetSettings.Type.RECENT) {
        // recent
        showsTabIndex = ShowsActivity.InitBundle.INDEX_TAB_RECENT;
        titleResId = R.string.recent;
        emptyResId = R.string.norecent;
    } else {
        // favorites
        showsTabIndex = ShowsActivity.InitBundle.INDEX_TAB_SHOWS;
        titleResId = R.string.action_shows_filter_favorites;
        emptyResId = R.string.no_nextepisode;
    }

    // change title and empty view based on type
    rv.setTextViewText(R.id.empty_view, context.getString(emptyResId));
    if (!isCompactLayout) {
        // only regular layout has text title
        rv.setTextViewText(R.id.widgetTitle, context.getString(titleResId));
    }

    // app launch button
    final Intent appLaunchIntent = new Intent(context, ShowsActivity.class)
            .putExtra(ShowsActivity.InitBundle.SELECTED_TAB, showsTabIndex);
    PendingIntent pendingIntent = TaskStackBuilder.create(context).addNextIntent(appLaunchIntent)
            .getPendingIntent(appWidgetId, PendingIntent.FLAG_UPDATE_CURRENT);
    rv.setOnClickPendingIntent(R.id.widget_title, pendingIntent);

    // item intent template, launches episode detail view
    TaskStackBuilder builder = TaskStackBuilder.create(context);
    builder.addNextIntent(appLaunchIntent);
    builder.addNextIntent(new Intent(context, EpisodesActivity.class));
    rv.setPendingIntentTemplate(R.id.list_view, builder.getPendingIntent(1, PendingIntent.FLAG_UPDATE_CURRENT));

    // settings button
    Intent settingsIntent = new Intent(context, ListWidgetConfigure.class)
            .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)
            .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    rv.setOnClickPendingIntent(R.id.widget_settings,
            PendingIntent.getActivity(context, appWidgetId, settingsIntent, PendingIntent.FLAG_UPDATE_CURRENT));

    return rv;
}

From source file:com.android.transmart.PlaceActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Inflate the layout
    setContentView(R.layout.nearby);/*from ww w.  j  av  a2 s .  com*/

    // Get a handle to the Fragments
    placeListFragment = (PlaceListFragment) getSupportFragmentManager().findFragmentById(R.id.list_fragment);
    checkinFragment = (CheckinFragment) getSupportFragmentManager().findFragmentById(R.id.checkin_fragment);

    // Get references to the managers
    packageManager = getPackageManager();
    notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    // Get a reference to the Shared Preferences and a Shared Preference Editor.
    prefs = getSharedPreferences(LocationConstants.SHARED_PREFERENCE_FILE, Context.MODE_PRIVATE);
    prefsEditor = prefs.edit();

    // Instantiate a SharedPreferenceSaver class based on the available platform version.
    // This will be used to save shared preferences
    sharedPreferenceSaver = PlatformSpecific.getSharedPreferenceSaver(this);

    // Save that we've been run once.
    prefsEditor.putBoolean(LocationConstants.SP_KEY_RUN_ONCE, true);
    sharedPreferenceSaver.savePreferences(prefsEditor, false);

    // Specify the Criteria to use when requesting location updates while the application is Active
    criteria = new Criteria();
    if (LocationConstants.USE_GPS_WHEN_ACTIVITY_VISIBLE)
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
    else
        criteria.setPowerRequirement(Criteria.POWER_LOW);

    // Setup the location update Pending Intents
    Intent activeIntent = new Intent(this, LocationChangedReceiver.class);
    locationListenerPendingIntent = PendingIntent.getBroadcast(this, 0, activeIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    Intent passiveIntent = new Intent(this, PassiveLocReceiver.class);
    locationListenerPassivePendingIntent = PendingIntent.getBroadcast(this, 0, passiveIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // Instantiate a LastLocationFinder class.
    // This will be used to find the last known location when the application starts.
    lastLocationFinder = PlatformSpecific.getLastLocationFinder(this);
    lastLocationFinder.setChangedLocationListener(oneShotLastLocationUpdateListener);

    // Instantiate a Location Update Requester class based on the available platform version.
    // This will be used to request location updates.
    locationUpdateRequester = PlatformSpecific.getLocationUpdateRequester(locationManager);

    // Create an Intent Filter to listen for checkins
    newCheckinReceiverName = new ComponentName(this, NewCheckinReceiver.class);
    newCheckinFilter = new IntentFilter(LocationConstants.NEW_CHECKIN_ACTION);

    // Check to see if an Place ID has been specified in the launch Intent.
    // If so, we should display the details for the specified venue.
    if (getIntent().hasExtra(LocationConstants.EXTRA_KEY_ID)) {
        Intent intent = getIntent();
        String key = intent.getStringExtra(LocationConstants.EXTRA_KEY_ID);
        if (key != null) {
            selectDetail(null, key);
            // Remove the ID from the Intent (so that a resume doesn't reselect).
            intent.removeExtra(LocationConstants.EXTRA_KEY_ID);
            setIntent(intent);
        }
    }
}

From source file:at.florian_lentsch.expirysync.NotifyChecker.java

private void createExpiryNotification(Context appContext, List<String> expiringProducts) {
    Resources res = appContext.getResources();
    NotificationCompat.Builder builder = new NotificationCompat.Builder(appContext)
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle(res.getQuantityString(R.plurals.numberOfItemsToBeEaten, expiringProducts.size(),
                    expiringProducts.size()))
            .setContentText(StringUtils.join(expiringProducts, System.getProperty("line.separator")))
            .setSound(Settings.System.DEFAULT_NOTIFICATION_URI).setAutoCancel(true);
    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(appContext, ProductListActivity.class);

    // set stack (for the back button to work correctly):
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(appContext);
    stackBuilder.addParentStack(ProductListActivity.class);
    stackBuilder.addNextIntent(resultIntent);

    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(resultPendingIntent);
    NotificationManager notificationManager = (NotificationManager) appContext
            .getSystemService(Context.NOTIFICATION_SERVICE);

    // display the notification:
    notificationManager.notify(WASTE_NOTIFICATION, builder.build());
}

From source file:com.amaze.filemanager.asynchronous.services.CopyService.java

@Override
public int onStartCommand(Intent intent, int flags, final int startId) {

    Bundle b = new Bundle();
    isRootExplorer = intent.getBooleanExtra(TAG_IS_ROOT_EXPLORER, false);
    ArrayList<HybridFileParcelable> files = intent.getParcelableArrayListExtra(TAG_COPY_SOURCES);
    String targetPath = intent.getStringExtra(TAG_COPY_TARGET);
    int mode = intent.getIntExtra(TAG_COPY_OPEN_MODE, OpenMode.UNKNOWN.ordinal());
    final boolean move = intent.getBooleanExtra(TAG_COPY_MOVE, false);
    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(c);
    accentColor = ((AppConfig) getApplication()).getUtilsProvider().getColorPreference()
            .getCurrentUserColorPreferences(this, sharedPreferences).accent;

    mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    b.putInt(TAG_COPY_START_ID, startId);

    Intent notificationIntent = new Intent(this, MainActivity.class);
    notificationIntent.setAction(Intent.ACTION_MAIN);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    notificationIntent.putExtra(MainActivity.KEY_INTENT_PROCESS_VIEWER, true);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    customSmallContentViews = new RemoteViews(getPackageName(), R.layout.notification_service_small);
    customBigContentViews = new RemoteViews(getPackageName(), R.layout.notification_service_big);

    Intent stopIntent = new Intent(TAG_BROADCAST_COPY_CANCEL);
    PendingIntent stopPendingIntent = PendingIntent.getBroadcast(c, 1234, stopIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Action action = new NotificationCompat.Action(R.drawable.ic_content_copy_white_36dp,
            getString(R.string.stop_ftp), stopPendingIntent);

    mBuilder = new NotificationCompat.Builder(c, NotificationConstants.CHANNEL_NORMAL_ID)
            .setContentIntent(pendingIntent).setSmallIcon(R.drawable.ic_content_copy_white_36dp)
            .setCustomContentView(customSmallContentViews).setCustomBigContentView(customBigContentViews)
            .setCustomHeadsUpContentView(customSmallContentViews)
            .setStyle(new NotificationCompat.DecoratedCustomViewStyle()).addAction(action).setOngoing(true)
            .setColor(accentColor);//from  w w  w  .j  a v  a  2 s .co m

    // set default notification views text

    NotificationConstants.setMetadata(c, mBuilder, NotificationConstants.TYPE_NORMAL);

    startForeground(NotificationConstants.COPY_ID, mBuilder.build());
    initNotificationViews();

    b.putBoolean(TAG_COPY_MOVE, move);
    b.putString(TAG_COPY_TARGET, targetPath);
    b.putInt(TAG_COPY_OPEN_MODE, mode);
    b.putParcelableArrayList(TAG_COPY_SOURCES, files);

    super.onStartCommand(intent, flags, startId);
    super.progressHalted();
    //going async
    new DoInBackground(isRootExplorer).execute(b);

    // If we get killed, after returning from here, restart
    return START_STICKY;
}