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:com.watabou.noosa.Game.java

public void doRestart() {
    Intent i = instance().getBaseContext().getPackageManager()
            .getLaunchIntentForPackage(getBaseContext().getPackageName());
    i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);

    int piId = 123456;
    PendingIntent pi = PendingIntent.getActivity(getBaseContext(), piId, i, PendingIntent.FLAG_CANCEL_CURRENT);
    AlarmManager mgr = (AlarmManager) getBaseContext().getSystemService(ContextWrapper.ALARM_SERVICE);
    mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, pi);
    shutdown();/*from ww w. j  av  a2 s  .com*/
}

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

private PendingIntent createClickedIntent(String flow, Bundle extras) {
    Intent intent = new Intent(this, DismissNotification.class);
    intent.setAction("notification_clicked");
    intent.putExtra("flow", flow);

    int requestCode = 0;
    if (extras.containsKey("flow_url")) {
        intent.putExtra("flow_url", extras.getString("flow_url"));
        requestCode = extras.getString("flow_url").hashCode();
    }// ww w.ja va2  s .co m

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

From source file:org.mozilla.gecko.tabqueue.TabQueueHelper.java

/**
 * Displays a notification showing the total number of tabs queue.  If there is already a notification displayed, it
 * will be replaced.//from w  w w.j  av a2 s.  c  o  m
 *
 * @param context
 * @param tabsQueued
 */
public static void showNotification(final Context context, final int tabsQueued) {
    ThreadUtils.assertNotOnUiThread();

    Intent resultIntent = new Intent();
    resultIntent.setClassName(context, AppConstants.MOZ_ANDROID_BROWSER_INTENT_CLASS);
    resultIntent.setAction(TabQueueHelper.LOAD_URLS_ACTION);

    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, resultIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    final String text;
    final Resources resources = context.getResources();
    if (tabsQueued == 1) {
        text = resources.getString(R.string.tab_queue_notification_text_singular);
    } else {
        text = resources.getString(R.string.tab_queue_notification_text_plural, tabsQueued);
    }

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_status_logo)
            .setContentTitle(resources.getString(R.string.tab_queue_notification_title)).setContentText(text)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(TabQueueHelper.TAB_QUEUE_NOTIFICATION_ID, builder.build());
}

From source file:org.catrobat.catroid.utils.StatusBarNotificationManager.java

public int createDownloadNotification(Context context, String programName) {
    if (context == null || programName == null) {
        return -1;
    }//from   w w w .  j av a  2s  .co  m
    initNotificationManager(context);

    Intent downloadIntent = new Intent(context, MainMenuActivity.class);
    downloadIntent.setAction(Intent.ACTION_MAIN).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
            .putExtra(EXTRA_PROJECT_NAME, programName);

    PendingIntent pendingIntent = PendingIntent.getActivity(context, notificationId, downloadIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    NotificationData data = new NotificationData(context, pendingIntent, R.drawable.ic_stat, programName,
            R.string.notification_download_title_pending, R.string.notification_title_open,
            R.string.notification_download_pending, R.string.notification_download_finished);

    return createNotification(context, data);
}

From source file:ca.hoogit.hooold.Scheduling.Sms.java

private ArrayList<PendingIntent> generateIntents(Context context, String action, String recipient,
        int recipientCount, int partCount) {
    ArrayList<PendingIntent> pendingIntents = new ArrayList<>();
    for (int i = 1; i <= partCount; i++) {
        Intent intent = generateIntent(action, recipient, recipientCount);
        intent.putExtra(Consts.KEY_SMS_PARTS, partCount);
        intent.putExtra(Consts.KEY_SMS_PART, i);

        PendingIntent pending = PendingIntent.getBroadcast(context, (int) id, intent,
                PendingIntent.FLAG_CANCEL_CURRENT);
        pendingIntents.add(pending);/*w  w w . j  a va2s.  co m*/
    }
    return pendingIntents;
}

From source file:com.conferenceengineer.android.iosched.service.SessionAlarmService.java

private void scheduleAlarm(final long sessionStart, final long sessionEnd, final long alarmOffset) {

    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    nm.cancel(NOTIFICATION_ID);//from ww  w  .jav a  2 s .  c o  m
    final long currentTime = UIUtils.getCurrentTime(this);
    // If the session is already started, do not schedule system notification.
    if (currentTime > sessionStart)
        return;

    // By default, sets alarm to go off at 10 minutes before session start time.  If alarm
    // offset is provided, alarm is set to go off by that much time from now.
    long alarmTime;
    if (alarmOffset == UNDEFINED_ALARM_OFFSET) {
        alarmTime = sessionStart - MILLI_TEN_MINUTES;
    } else {
        alarmTime = currentTime + alarmOffset;
    }

    final Intent notifIntent = new Intent(ACTION_NOTIFY_SESSION, null, this, SessionAlarmService.class);
    // Setting data to ensure intent's uniqueness for different session start times.
    notifIntent.setData(new Uri.Builder().authority("com.conferenceengineer.android.iosched")
            .path(String.valueOf(sessionStart)).build());
    notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_START, sessionStart);
    notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_END, sessionEnd);
    notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_ALARM_OFFSET, alarmOffset);
    PendingIntent pi = PendingIntent.getService(this, 0, notifIntent, PendingIntent.FLAG_CANCEL_CURRENT);
    final AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    // Schedule an alarm to be fired to notify user of added sessions are about to begin.
    am.set(AlarmManager.RTC_WAKEUP, alarmTime, pi);
}

From source file:com.smart.taxi.GcmIntentService.java

private void sendNotification(Object msg) {
    Intent intent;/*from  w  ww.  ja  v  a2s  .co  m*/
    String message;
    int rid = r.nextInt(1800 - 650) + 650;
    try {
        Bundle extras = (Bundle) msg;
        String notifType = (Utils.isEmptyOrNull(extras.getString("type"))
                && extras.getString("status").equals("1")) ? "accept" : extras.getString("type");
        String journeyId = extras.getString("journey_id");
        message = extras.getString("message");

        intent = new Intent(DISPLAY_MESSAGE_ACTION);

        intent.putExtra("rid", rid);
        intent.putExtra("journeyId", journeyId);
        intent.putExtra("type", notifType);
        intent.putExtra("message", (Utils.isEmptyOrNull(message)) ? "" : message);
        getApplicationContext().sendBroadcast(intent);

    } catch (Exception ex) {
        return;
    }

    Intent notifIntent = new Intent("com.smart.taxi.beep");
    notifIntent.putExtra("msg", (Utils.isEmptyOrNull(message)) ? "Beep recevied" : message);
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notifIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    //Define sound URI
    Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle(getString(R.string.app_name))
            .setStyle(new NotificationCompat.InboxStyle().addLine(msg.toString())).setContentText(message)
            .setSound(soundUri).setDefaults(Notification.DEFAULT_VIBRATE);

    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(rid, mBuilder.build());
}

From source file:ru.orangesoftware.financisto.activity.FlowzrSyncActivity.java

public void initProgressDialog() {
    Intent notificationIntent = new Intent(getApplicationContext(), FlowzrSyncActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    mNotifyBuilder.setContentIntent(contentIntent).setSmallIcon(R.drawable.icon)
            .setWhen(System.currentTimeMillis()).setAutoCancel(true)
            .setContentTitle(getApplicationContext().getString(R.string.flowzr_sync))
            .setContentText(getApplicationContext().getString(R.string.flowzr_sync_auth_inprogress));
    nm.notify(NOTIFICATION_ID, mNotifyBuilder.build());
}

From source file:info.papdt.blacklight.support.Utility.java

public static void stopServiceAlarm(Context context, Class<?> service) {
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent i = new Intent(context, service);
    PendingIntent p = PendingIntent.getService(context, REQUEST_CODE, i, PendingIntent.FLAG_CANCEL_CURRENT);
    am.cancel(p);/*from  w ww .  ja  v a2 s.  c om*/
}

From source file:net.frygo.findmybuddy.GCMIntentService.java

private static void generateAcceptfriendNotification(Context context, String message, String status) {

    Random rand = new Random();
    int x = rand.nextInt();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    String title = context.getString(R.string.app_name);
    Intent notificationIntent = new Intent(context, customlistview.class);
    if (status.equalsIgnoreCase("accept"))
        message = message + " added you as buddy";
    else//  ww  w .java2 s .  c o  m
        message = message + " rejected you as buddy";
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_CANCEL_CURRENT);

    Notification notification = new Notification(R.drawable.logo, message, System.currentTimeMillis());
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    notification.setLatestEventInfo(context, title, message, intent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(x, notification);

    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    final PowerManager.WakeLock mWakelock = pm
            .newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, title);
    mWakelock.acquire();

    // Timer before putting Android Device to sleep mode.
    Timer timer = new Timer();
    TimerTask task = new TimerTask() {
        public void run() {
            mWakelock.release();
        }
    };
    timer.schedule(task, 5000);

}