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.awt.supark.ParkingTimerService.java

private void createNotification(final int id, final String licenseNum, final String formattedEndTime,
        final long remainingTime, final long parkedTime, final long parkedUntil, boolean alert) {
    try {//from   ww  w.ja v  a2  s  .c om
        // Cancel button action
        Intent cancelIntent = new Intent(ACTION_CANCEL);
        cancelIntent.putExtra("cancelId", id);
        PendingIntent pIntentCancel = PendingIntent.getBroadcast(this, id, cancelIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        // Renew button action
        Intent renewIntent = new Intent(ACTION_RENEW);
        renewIntent.putExtra("renewId", id);
        PendingIntent pIntentRenew = PendingIntent.getBroadcast(this, id, renewIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        mNotification = new NotificationCompat.Builder(getApplicationContext()); // Setting the notification parameters:
        mNotification.setSmallIcon(R.mipmap.ic_directions_car_white_24dp); // * icon
        mNotification.setOngoing(true); // * making it ongoing so the user can't swipe away
        mNotification.setContentTitle(
                getResources().getString(R.string.parking_status_of) + " " + licenseNum.toUpperCase()); // * title
        mNotification.setContentText(
                remainingTime + " " + getResources().getString(R.string.minutes_left) + " " + formattedEndTime); // * content text
        mNotification.setProgress((int) (parkedUntil - parkedTime), (int) remainingTime * 60, false); // * progress bar to visualize the remaining time
        mNotification.addAction(R.mipmap.ic_highlight_off_white_24dp, getResources().getString(R.string.cancel),
                pIntentCancel); // * cancel button

        // Playing alert if the alerts are turned on
        if (alert && sharedPreferences.getBoolean("alertBefore", true)) {
            mNotification.setSound(soundUri);
            mNotification.setLights(Color.RED, 3000, 3000);
            mNotification.setVibrate(new long[] { 1000, 1000 });
        }

        notificationManager.notify(id, mNotification.build()); // Finally we can build the actual notification where the ID is the selected car's ID

    } catch (Exception e) {
        Log.i("Service", "Failed to create notification for ID: " + id);
        Log.i("Service", "Exception: " + e.toString());
    }
}

From source file:com.vidinoti.pixlive.PixLive.java

static void startSDK(final Context c) {

    if (VDARSDKController.getInstance() != null) {
        return;/*www.  jav a  2 s  . c o  m*/
    }

    String storage = c.getApplicationContext().getFilesDir().getAbsolutePath() + "/pixliveSDK";

    String licenseKey = null;

    try {
        ApplicationInfo ai = c.getPackageManager().getApplicationInfo(c.getPackageName(),
                PackageManager.GET_META_DATA);
        Bundle bundle = ai.metaData;
        licenseKey = bundle.getString("com.vidinoti.pixlive.LicenseKey");
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(TAG, "Unable to start PixLive SDK without valid storage and license key.");
        return;
    } catch (NullPointerException e) {
        Log.e(TAG, "Unable to start PixLive SDK without valid storage and license key.");
        return;
    }

    if (storage == null || licenseKey == null) {
        Log.e(TAG, "Unable to start PixLive SDK without valid storage and license key.");
        return;
    }

    VDARSDKController.startSDK(c, storage, licenseKey);

    /* Comment out to disable QR code detection */
    VDARSDKController.getInstance().setEnableCodesRecognition(true);

    VDARSDKController.getInstance().setNotificationFactory(new NotificationFactory() {

        @Override
        public Notification createNotification(String title, String message, String notificationID) {

            Intent appIntent = c.getPackageManager().getLaunchIntentForPackage(c.getPackageName());

            appIntent.putExtra("nid", notificationID);
            appIntent.putExtra("remote", false);

            PendingIntent contentIntent = PendingIntent.getActivity(c, 0, appIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT);

            ApplicationInfo ai = c.getApplicationInfo();

            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(c)
                    .setSmallIcon(ai.icon != 0 ? ai.icon : android.R.drawable.star_big_off)
                    .setContentTitle(title).setContentText(message).setContentIntent(contentIntent)
                    .setAutoCancel(true).setVibrate(new long[] { 100, 200, 200, 400 })
                    .setLights(Color.BLUE, 500, 1500);

            mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));

            return mBuilder.getNotification();
        }
    });
}

From source file:at.ac.uniklu.mobile.sportal.service.MutingService.java

/**
 * Turns OFF automatic ringtone muting during courses.
 *///from  www . j a va2s .co  m
private void turnOff() {
    Log.d(TAG, "turnOff()");
    Analytics.onEvent(Analytics.EVENT_MUTINGSERVICE_OFF);

    // if the phone is currently in a muting period, turn the ringtone back on before turning off the service
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
    if (Preferences.isMutingPeriod(preferences)) {
        MutingUtils.ringtoneTurnOn(this);
        Preferences.setMutingPeriod(preferences, false);
    }

    // remove eventually existing user notification
    removeNotification(Studentportal.NOTIFICATION_MS_INFO);

    // cancel an eventually existing pending alarm and the beloging intent as well (otherwise isRunning would always return true)
    AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    Intent alarmIntent = new Intent(this, OnAlarmReceiver.class).putExtra(ACTION, ACTION_NONE);
    PendingIntent pendingAlarmIntent = PendingIntent.getBroadcast(this, 0, alarmIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    alarmManager.cancel(pendingAlarmIntent);
    pendingAlarmIntent.cancel();

    // cancel an eventually exisiting location broadcast receiver
    LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    Intent locationIntent = new Intent("at.ac.uniklu.mobile.sportal.LOCATION_UPDATE");
    PendingIntent pendingLocationIntent = PendingIntent.getBroadcast(this, 0, locationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    locationManager.removeUpdates(pendingLocationIntent);
    pendingLocationIntent.cancel();

    if (isRunning()) {
        Log.e(TAG, "COULD NOT TURN OFF");
    }
}

From source file:com.tcs.geofenceplugin.GeofenceTransitionsIntentService.java

private void sendNotification(String notificationDetails, String contenttext, String place) {
    Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(notificationIntent);
    PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0,
            PendingIntent.FLAG_UPDATE_CURRENT);

    notificationDetails = notificationDetails.substring(0, notificationDetails.length() - 1);

    Notification n = new Notification.Builder(this).setContentTitle("Entered :" + place)
            .setContentText(contenttext).setSmallIcon(R.drawable.ic_launcher)
            .setContentIntent(notificationPendingIntent).setAutoCancel(true)
            .setDefaults(Notification.DEFAULT_ALL).build();

    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationManager.notify(0, n);//from  w ww.ja v  a2 s  . c  o m

}

From source file:com.aware.ESM.java

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

    TAG = Aware.getSetting(getApplicationContext(), Aware_Preferences.DEBUG_TAG).length() > 0
            ? Aware.getSetting(getApplicationContext(), Aware_Preferences.DEBUG_TAG)
            : TAG;/* ww  w.  j a  va  2s  . com*/

    DATABASE_TABLES = ESM_Provider.DATABASE_TABLES;
    TABLES_FIELDS = ESM_Provider.TABLES_FIELDS;
    CONTEXT_URIS = new Uri[] { ESM_Data.CONTENT_URI };

    IntentFilter filter = new IntentFilter();
    filter.addAction(ESM.ACTION_AWARE_QUEUE_ESM);
    registerReceiver(esmMonitor, filter);

    intent_ESM = new Intent(this, ESM_Queue.class);
    intent_ESM.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    pending_ESM = PendingIntent.getActivity(this, 0, intent_ESM, PendingIntent.FLAG_UPDATE_CURRENT);

    if (Aware.DEBUG)
        Log.d(TAG, "ESM service created!");
}

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

/**
 * Make a new notification builder with common attributes already set.
 *
 * @param context         context/*from   w ww.  ja v  a  2s  . c  o m*/
 * @param currentTime     timestamp to display in the notification
 * @param dismissedTaskId ID of the task to dismiss with this notification, or {@link Task#NO_ID} to dismiss all
 * @return partially pre-configured notification builder
 */
private static NotificationCompat.Builder makeCommonBuilder(Context context, long currentTime,
        long dismissedTaskId) {
    // When notification is clicked, simply go to the app
    Intent primaryAction = new Intent(context, MainActivity.class);
    PendingIntent primaryActionPI = PendingIntent.getActivity(context, 0, primaryAction,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // When notification is dismissed, tell the service to handle it properly
    Intent dismissAction = new Intent(context, NagboxService.class);
    dismissAction.setAction(NagboxService.ACTION_ON_NOTIFICATION_DISMISSED);
    dismissAction.putExtra(NagboxService.EXTRA_TASK_ID, dismissedTaskId);
    // Just as well, this pending intent needs a unique request code, otherwise it will be overwritten
    PendingIntent dismissActionPI = PendingIntent.getService(context, (int) dismissedTaskId, dismissAction,
            PendingIntent.FLAG_UPDATE_CURRENT);

    return new NotificationCompat.Builder(context).setSmallIcon(R.drawable.ic_nag)
            .setColor(ContextCompat.getColor(context, R.color.primaryDark))
            .setCategory(NotificationCompat.CATEGORY_REMINDER).setPriority(NotificationCompat.PRIORITY_HIGH)
            .setContentIntent(primaryActionPI).setDeleteIntent(dismissActionPI).setAutoCancel(true)
            .setWhen(currentTime).setShowWhen(true).setDefaults(NotificationCompat.DEFAULT_ALL);
}

From source file:at.software2014.trackme.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mServerInterface = new ServerComm();

    registerUserAtFirstLaunch();/*w w  w.j  a  va  2  s  .  c o m*/

    SharedPreferences prefs = getSharedPreferences(TRACK_ME_PREFERENCES, MODE_PRIVATE);
    mEMail = prefs.getString("email", "");
    mName = prefs.getString("first_name", "");

    mDisableServerComm = getDisableServerComm();
    mDisableLocation = getDisableLocationServices();

    mContacts = new ArrayList<ContactEntry>();
    mRegisteredUsers = new ArrayList<ContactEntry>();

    mLocationRequest = LocationRequest.create();
    mLocationClient = new LocationClient(this, this, this);

    setLocationPriority(true, false);

    mTitle = getTitle();
    mMenuTitles = getResources().getStringArray(R.array.navigation_menu);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerLinear = (LinearLayout) findViewById(R.id.drawer_linear_layout);
    mDrawerText = (TextView) findViewById(R.id.left_drawer_text);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

    mDrawerText.setText(mName);

    mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mMenuTitles));
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description for accessibility */
            R.string.drawer_close /* "close drawer" description for accessibility */
    ) {
        public void onDrawerClosed(View view) {
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }

        public void onDrawerOpened(View drawerView) {
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }
    };

    mDrawerLayout.setDrawerListener(mDrawerToggle);

    //if (savedInstanceState == null) {
    //   if(isGooglePlayServicesConnected()){            
    //      selectItem(0, "");
    //   }
    //}

    if (mDisableLocation == false) {
        Intent intent = new Intent(this, LocationUpdatesIntentService.class);
        intent.putExtra("eMail", mEMail);
        mLocationUpdatesPendingIntent = PendingIntent.getService(this, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
    }

}

From source file:com.android.fpuna.activityrecognition.MainActivity.java

/**
 * Gets a PendingIntent to be sent for each activity detection.
 *//*from   w w w .j  a  va  2s . c  o  m*/
private PendingIntent getActivityDetectionPendingIntent() {
    // Reuse the PendingIntent if we already have it.
    if (mActivityDetectionPendingIntent != null) {
        return mActivityDetectionPendingIntent;
    }
    Intent intent = new Intent(this, DetectedActivitiesIntentService.class);

    // We use FLAG_UPDATE_CURRENT so that we get the same pending intent back when calling
    // requestActivityUpdates() and removeActivityUpdates().
    return PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}

From source file:ca.rmen.android.poetassistant.PoemAudioExport.java

private PendingIntent getFileShareIntent() {
    // Bring up the chooser to share the file.
    Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_SEND);
    Uri uri = FileProvider.getUriForFile(mContext, BuildConfig.APPLICATION_ID + ".fileprovider",
            getAudioFile());/*  w  w  w.  j a va2 s . c o  m*/
    sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
    sendIntent.setType("audio/x-wav");
    return PendingIntent.getActivity(mContext, 0, sendIntent, PendingIntent.FLAG_UPDATE_CURRENT);
}

From source file:com.brightsilence.dev.androidphotobackup.PhotoBackupService.java

private void doNotification(String notificationText) {
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle("Android Photo Backup Complete")
            .setContentText(notificationText);

    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(this, PhotoBackupSettingsActivity.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(this);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(PhotoBackupSettingsActivity.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);
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    // mId allows you to update the notification later on.
    mNotificationManager.notify(m_notificationId, mBuilder.build());
}