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:net.hyx.app.volumenotification.factory.NotificationFactory.java

public void create() {
    int id = 1;//  w ww.ja  v a2s.c  o m
    cancel();
    if (settings.getEnabled()) {
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setOngoing(true)
                .setPriority(getPriority()).setVisibility(getVisibility())
                .setCustomContentView(getCustomContentView())
                .setSmallIcon((settings.getHideStatus()) ? android.R.color.transparent : R.drawable.ic_launcher)
                .setColor(Color.TRANSPARENT);

        PendingIntent deleteIntent = PendingIntent.getBroadcast(context.getApplicationContext(), 0,
                new Intent(context, CreateNotificationReceiver.class), PendingIntent.FLAG_CANCEL_CURRENT);

        builder.setDeleteIntent(deleteIntent);
        manager.notify(id, builder.build());
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        requestListeningTiles();
    }
}

From source file:com.example.android.mediabrowserservice.MediaNotificationManager.java

public MediaNotificationManager(MusicService service) {
    mService = service;/*w  w  w.  j  a  v a 2  s  . c o m*/
    updateSessionToken();

    mNotificationColor = ResourceHelper.getThemeColor(mService, android.R.attr.colorPrimary, Color.DKGRAY);

    mNotificationManager = (NotificationManager) mService.getSystemService(Context.NOTIFICATION_SERVICE);

    String pkg = mService.getPackageName();
    mPauseIntent = PendingIntent.getBroadcast(mService, REQUEST_CODE, new Intent(ACTION_PAUSE).setPackage(pkg),
            PendingIntent.FLAG_CANCEL_CURRENT);
    mPlayIntent = PendingIntent.getBroadcast(mService, REQUEST_CODE, new Intent(ACTION_PLAY).setPackage(pkg),
            PendingIntent.FLAG_CANCEL_CURRENT);
    mPreviousIntent = PendingIntent.getBroadcast(mService, REQUEST_CODE,
            new Intent(ACTION_PREV).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT);
    mNextIntent = PendingIntent.getBroadcast(mService, REQUEST_CODE, new Intent(ACTION_NEXT).setPackage(pkg),
            PendingIntent.FLAG_CANCEL_CURRENT);

    // Cancel all notifications to handle the case where the Service was killed and
    // restarted by the system.
    mNotificationManager.cancelAll();
}

From source file:com.example.android.background.utilities.NotificationUtils.java

private static Action drinkWaterAction(Context context) {
    Intent incrementWaterCountIntent = new Intent(context, WaterReminderIntentService.class);
    incrementWaterCountIntent.setAction(ReminderTasks.ACTION_INCREMENT_WATER_COUNT);
    PendingIntent incrementWaterPendingIntent = PendingIntent.getService(context,
            ACTION_DRINK_PENDING_INTENT_ID, incrementWaterCountIntent, PendingIntent.FLAG_CANCEL_CURRENT);
    Action drinkWaterAction = new Action(R.drawable.ic_local_drink_black_24px, "I did it!",
            incrementWaterPendingIntent);
    return drinkWaterAction;
}

From source file:com.example.android.elizachat.ResponderService.java

private void showNotification() {
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "Sent: " + mLastResponse);
    }// w  ww  .  j  a v a  2s .c o m
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setContentTitle(getString(R.string.eliza)).setContentText(mLastResponse)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.bg_eliza))
            .setSmallIcon(R.drawable.bg_eliza).setPriority(NotificationCompat.PRIORITY_MIN);

    Intent intent = new Intent(ACTION_RESPONSE);
    PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent,
            PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT);
    Notification notification = builder.extend(new NotificationCompat.WearableExtender()
            .addAction(new NotificationCompat.Action.Builder(R.drawable.ic_full_reply,
                    getString(R.string.reply), pendingIntent).addRemoteInput(
                            new RemoteInput.Builder(EXTRA_REPLY).setLabel(getString(R.string.reply)).build())
                            .build()))
            .build();
    NotificationManagerCompat.from(this).notify(0, notification);
}

From source file:com.cyanogenmod.account.util.CMAccountUtils.java

public static void scheduleCMAccountPing(Context context, Intent intent) {
    if (CMAccount.DEBUG)
        Log.d(TAG,/*  ww  w .ja  v  a  2 s  . co  m*/
                "Scheduling CMAccount ping, starting = "
                        + new Timestamp(SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_DAY)
                        + " interval (" + AlarmManager.INTERVAL_DAY + ")");
    PendingIntent reRegisterPendingIntent = PendingIntent.getService(context, 0, intent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME,
            SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_DAY, AlarmManager.INTERVAL_DAY,
            reRegisterPendingIntent);
}

From source file:br.ajmarques.cordova.plugin.localnotification.LocalNotification.java

/**
 * Cancel a specific notification that was previously registered.
 *
 * @param notificationId/*  w w w.  ja va2  s  .c o  m*/
 *            The original ID of the notification that was used when it was
 *            registered using add()
 */
public static void cancel(String notificationId) {
    /*
     * Create an intent that looks similar, to the one that was registered
     * using add. Making sure the notification id in the action is the same.
     * Now we can search for such an intent using the 'getService' method
     * and cancel it.
     */

    Intent intent = new Intent(context, Receiver.class).setAction("" + notificationId);

    PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
    AlarmManager am = getAlarmManager();
    NotificationManager nc = getNotificationManager();

    am.cancel(pi);

    try {
        nc.cancel(Integer.parseInt(notificationId));
    } catch (Exception e) {
    }
}

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

public MediaNotificationManager(MusicService service) throws RemoteException {
    mService = service;/*  w ww  . j ava  2  s  . c o m*/
    updateSessionToken();

    mNotificationColor = ResourceHelper.getThemeColor(mService, R.attr.colorPrimary, Color.DKGRAY);

    mNotificationManager = NotificationManagerCompat.from(service);

    String pkg = mService.getPackageName();
    mPauseIntent = PendingIntent.getBroadcast(mService, REQUEST_CODE, new Intent(ACTION_PAUSE).setPackage(pkg),
            PendingIntent.FLAG_CANCEL_CURRENT);
    mPlayIntent = PendingIntent.getBroadcast(mService, REQUEST_CODE, new Intent(ACTION_PLAY).setPackage(pkg),
            PendingIntent.FLAG_CANCEL_CURRENT);
    mPreviousIntent = PendingIntent.getBroadcast(mService, REQUEST_CODE,
            new Intent(ACTION_PREV).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT);
    mNextIntent = PendingIntent.getBroadcast(mService, REQUEST_CODE, new Intent(ACTION_NEXT).setPackage(pkg),
            PendingIntent.FLAG_CANCEL_CURRENT);
    mStopCastIntent = PendingIntent.getBroadcast(mService, REQUEST_CODE,
            new Intent(ACTION_STOP_CASTING).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT);

    mNotificationManager.cancelAll();
}

From source file:com.example.android.wearable.elizachat.ResponderService.java

private void showNotification() {
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "Sent: " + mLastResponse);
    }/*from  w  ww  .  j  a v a 2 s  .co  m*/
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setContentTitle(getString(R.string.eliza)).setContentText(mLastResponse)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.bg_eliza))
            .setSmallIcon(R.drawable.bg_eliza).setPriority(NotificationCompat.PRIORITY_DEFAULT);

    Intent intent = new Intent(ACTION_RESPONSE);
    PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent,
            PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT);
    Notification notification = builder.extend(new NotificationCompat.WearableExtender()
            .addAction(new NotificationCompat.Action.Builder(R.drawable.ic_full_reply,
                    getString(R.string.reply), pendingIntent).addRemoteInput(
                            new RemoteInput.Builder(EXTRA_REPLY).setLabel(getString(R.string.reply)).build())
                            .build()))
            .build();
    NotificationManagerCompat.from(this).notify(0, notification);
}

From source file:com.morlunk.mumbleclient.service.PlumbleReconnectNotification.java

public void show(String error, boolean autoReconnect) {
    IntentFilter filter = new IntentFilter();
    filter.addAction(BROADCAST_DISMISS);
    filter.addAction(BROADCAST_RECONNECT);
    filter.addAction(BROADCAST_CANCEL_RECONNECT);
    try {/*w  ww  .  j a v a  2  s.c  o m*/
        mContext.registerReceiver(mNotificationReceiver, filter);
    } catch (IllegalArgumentException e) {
        // Thrown if receiver is already registered.
        e.printStackTrace();
    }
    NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext);
    builder.setSmallIcon(R.drawable.ic_stat_notify);
    builder.setPriority(NotificationCompat.PRIORITY_MAX);
    builder.setDefaults(NotificationCompat.DEFAULT_VIBRATE | NotificationCompat.DEFAULT_LIGHTS);
    builder.setContentTitle(mContext.getString(R.string.plumbleDisconnected));
    builder.setContentText(error);
    builder.setTicker(mContext.getString(R.string.plumbleDisconnected));

    Intent dismissIntent = new Intent(BROADCAST_DISMISS);
    builder.setDeleteIntent(
            PendingIntent.getBroadcast(mContext, 2, dismissIntent, PendingIntent.FLAG_CANCEL_CURRENT));

    if (autoReconnect) {
        Intent cancelIntent = new Intent(BROADCAST_CANCEL_RECONNECT);
        builder.addAction(R.drawable.ic_action_delete_dark, mContext.getString(R.string.cancel_reconnect),
                PendingIntent.getBroadcast(mContext, 2, cancelIntent, PendingIntent.FLAG_CANCEL_CURRENT));
        builder.setOngoing(true);
    } else {
        Intent reconnectIntent = new Intent(BROADCAST_RECONNECT);
        builder.addAction(R.drawable.ic_action_move, mContext.getString(R.string.reconnect),
                PendingIntent.getBroadcast(mContext, 2, reconnectIntent, PendingIntent.FLAG_CANCEL_CURRENT));
    }

    NotificationManagerCompat nmc = NotificationManagerCompat.from(mContext);
    nmc.notify(NOTIFICATION_ID, builder.build());
}

From source file:com.phonemetra.account.util.AccountUtils.java

public static void scheduleAccountPing(Context context, Intent intent) {
    if (Account.DEBUG)
        Log.d(TAG,/* w w w .  j av a 2  s  .c o  m*/
                "Scheduling Account ping, starting = "
                        + new Timestamp(SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_DAY)
                        + " interval (" + AlarmManager.INTERVAL_DAY + ")");
    PendingIntent reRegisterPendingIntent = PendingIntent.getService(context, 0, intent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME,
            SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_DAY, AlarmManager.INTERVAL_DAY,
            reRegisterPendingIntent);
}