Example usage for android.app PendingIntent FLAG_CANCEL_CURRENT

List of usage examples for android.app PendingIntent FLAG_CANCEL_CURRENT

Introduction

In this page you can find the example usage for android.app PendingIntent FLAG_CANCEL_CURRENT.

Prototype

int FLAG_CANCEL_CURRENT

To view the source code for android.app PendingIntent FLAG_CANCEL_CURRENT.

Click Source Link

Document

Flag indicating that if the described PendingIntent already exists, the current one should be canceled before generating a new one.

Usage

From source file:fr.neamar.notiflow.GcmIntentService.java

private PendingIntent createDismissedIntent(String flow) {

    Intent intent = new Intent(this, DismissNotification.class);
    intent.setAction("notification_cancelled");
    intent.putExtra("flow", flow);
    int requestCode = flow.hashCode();

    return PendingIntent.getBroadcast(this, requestCode, intent, PendingIntent.FLAG_CANCEL_CURRENT);
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.AppReferenceObj.java

@Override
public void handleDirectMessage(Context context, Contact from, JSONObject obj) {
    String packageName = obj.optString(PACKAGE_NAME);
    String arg = obj.optString(ARG);
    Intent launch = new Intent();
    launch.setAction(Intent.ACTION_MAIN);
    launch.addCategory(Intent.CATEGORY_LAUNCHER);
    launch.putExtra(AppState.EXTRA_APPLICATION_ARGUMENT, arg);
    launch.putExtra("creator", false);
    launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    launch.setPackage(packageName);/*from   w w w  . j a v  a  2 s .  c  o m*/
    final PackageManager mgr = context.getPackageManager();
    List<ResolveInfo> resolved = mgr.queryIntentActivities(launch, 0);
    if (resolved == null || resolved.size() == 0) {
        Toast.makeText(context, "Could not find application to handle invite", Toast.LENGTH_SHORT).show();
        return;
    }
    ActivityInfo info = resolved.get(0).activityInfo;
    launch.setComponent(new ComponentName(info.packageName, info.name));
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, launch,
            PendingIntent.FLAG_CANCEL_CURRENT);

    (new PresenceAwareNotify(context)).notify("New Invitation", "Invitation received from " + from.name,
            "Click to launch application.", contentIntent);
}

From source file:com.android.settings.sim.SimSelectNotification.java

private void createNotification(Context context) {
    final Resources resources = context.getResources();
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_sim_card_alert_white_48dp)
            .setColor(context.getColor(R.color.sim_noitification))
            .setContentTitle(resources.getString(R.string.sim_notification_title))
            .setContentText(resources.getString(R.string.sim_notification_summary));
    Intent resultIntent = new Intent(context, SimSettingsActivity.class);
    resultIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    builder.setContentIntent(resultPendingIntent);
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(NOTIFICATION_ID, builder.build());
}

From source file:com.commontime.plugin.notification.notification.Builder.java

/**
 * Set intent to handle the click event. Will bring the app to
 * foreground.//from  w  w w.ja  va2  s . c om
 *
 * @param builder
 *      Local notification builder instance
 */
private void applyContentReceiver(NotificationCompat.Builder builder) {

    if (clickActivity == null)
        return;

    Intent intent = new Intent(context, clickActivity).putExtra(Options.EXTRA, options.toString())
            .setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);

    int requestCode = new Random().nextInt();

    PendingIntent contentIntent = PendingIntent.getActivity(context, requestCode, intent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    builder.setContentIntent(contentIntent);
}

From source file:com.android.settings.sim.SimBootReceiver.java

private void createNotification(Context context) {
    final Resources resources = context.getResources();

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_sim_card_alert_white_48dp)
            .setColor(resources.getColor(R.color.sim_noitification))
            .setContentTitle(resources.getString(R.string.sim_notification_title))
            .setContentText(resources.getString(R.string.sim_notification_summary));
    Intent resultIntent = new Intent(context, SimSettingsActivity.class);
    resultIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    builder.setContentIntent(resultPendingIntent);
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(NOTIFICATION_ID, builder.build());
}

From source file:com.sean.takeastand.alarmprocess.UnscheduledRepeatingAlarm.java

private PendingIntent createPendingIntent(Context context) {
    Intent intent = new Intent(context, AlarmReceiver.class);
    return PendingIntent.getBroadcast(context, REPEATING_ALARM_ID, intent, PendingIntent.FLAG_CANCEL_CURRENT);
}

From source file:at.bitfire.davdroid.AccountSettings.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public AccountSettings(@NonNull Context context, @NonNull Account account) throws InvalidAccountException {
    this.context = context;
    this.account = account;

    accountManager = AccountManager.get(context);

    synchronized (AccountSettings.class) {
        String versionStr = accountManager.getUserData(account, KEY_SETTINGS_VERSION);
        if (versionStr == null)
            throw new InvalidAccountException(account);

        int version = 0;
        try {//  w  w w. jav  a2s  .  c o m
            version = Integer.parseInt(versionStr);
        } catch (NumberFormatException ignored) {
        }
        App.log.info("Account " + account.name + " has version " + version + ", current version: "
                + CURRENT_VERSION);

        if (version < CURRENT_VERSION) {
            Notification notify = new NotificationCompat.Builder(context)
                    .setSmallIcon(R.drawable.ic_new_releases_light).setLargeIcon(App.getLauncherBitmap(context))
                    .setContentTitle(context.getString(R.string.settings_version_update))
                    .setContentText(context.getString(R.string.settings_version_update_settings_updated))
                    .setSubText(context.getString(R.string.settings_version_update_install_hint))
                    .setStyle(new NotificationCompat.BigTextStyle()
                            .bigText(context.getString(R.string.settings_version_update_settings_updated)))
                    .setCategory(NotificationCompat.CATEGORY_SYSTEM)
                    .setPriority(NotificationCompat.PRIORITY_HIGH)
                    .setContentIntent(PendingIntent.getActivity(context, 0,
                            new Intent(Intent.ACTION_VIEW, Constants.webUri.buildUpon()
                                    .appendEncodedPath("faq/entry/davdroid-not-working-after-update/").build()),
                            PendingIntent.FLAG_CANCEL_CURRENT))
                    .setLocalOnly(true).build();
            NotificationManagerCompat nm = NotificationManagerCompat.from(context);
            nm.notify(Constants.NOTIFICATION_ACCOUNT_SETTINGS_UPDATED, notify);

            update(version);
        }
    }
}

From source file:com.lloydtorres.stately.push.TrixHelper.java

/**
 * Cancels any previous alarms set for Alphys.
 * @param c App context./*  www.j  a  v a 2 s.c o  m*/
 */
public static void stopAlarmForAlphys(Context c) {
    Intent alphysIntent = new Intent(c, AlphysService.class);
    PendingIntent pendingIntent = PendingIntent.getService(c, 0, alphysIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    AlarmManager am = (AlarmManager) c.getSystemService(Context.ALARM_SERVICE);
    am.cancel(pendingIntent);
}

From source file:com.readystatesoftware.android.geras.mqtt.GerasMqttService.java

private void showNotification() {

    Intent intent = new Intent(getApplicationContext(), mNotificationTarget);
    PendingIntent target = PendingIntent.getActivity(getApplicationContext(), 0, intent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setOngoing(true)
            .setContentTitle("Geras MQTT service running").setContentText("Sensors are active")
            .setSmallIcon(R.drawable.ic_stat_active).setContentIntent(target);
    // issue the notification
    startForeground(NOTIFICATION_ID, builder.build());
}

From source file:geofence.GeofenceTransitionsIntentService.java

/**
 * Posts a notification in the notification bar when a transition is detected.
 * If the user clicks the notification, control goes to the MapsActivity -> POIActivity.
 *//*from w  w w  . j a v a2 s  .  co m*/
private void sendNotification(String notificationDetails) {
    // Create an explicit content Intent that starts the main Activity.
    Intent notificationIntent = new Intent(getApplicationContext(), MapsActivity.class);
    notificationIntent.setAction(STARTPOI);
    notificationIntent.putExtra(MapsActivity.POINT, name);
    notificationIntent.putExtra(MainActivity.TOURNAME, tourName);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    // Get a PendingIntent containing the entire back stack.
    PendingIntent notificationPendingIntent =
            //                stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
            PendingIntent.getActivity(this, PendingIntent.FLAG_CANCEL_CURRENT, notificationIntent, 0);
    //                PendingIntent.getBroadcast(this, PendingIntent.FLAG_CANCEL_CURRENT, notificationIntent, 0);

    // Get a notification builder that's compatible with platform versions >= 4
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

    // Define the notification settings.
    builder.setSmallIcon(R.mipmap.ic_launcher)
            // In a real app, you may want to use a library like Volley
            // to decode the Bitmap.
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
            .setColor(Color.RED).setContentTitle(notificationDetails).setContentText("Notification")
            .setContentIntent(notificationPendingIntent);

    // Dismiss notification once the user touches it.
    builder.setAutoCancel(true);

    // Get an instance of the Notification manager
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    // Issue the notification
    mNotificationManager.notify(TAG, 0, builder.build());
}