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:info.papdt.blacklight.support.Utility.java

public static void startServiceAlarm(Context context, Class<?> service, long interval) {
    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.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, 0, interval, p);
}

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

/**
 * Set intent to handle the delete event. Will clean up some persisted
 * preferences.//w w w . j  a  va2s  . c  o m
 *
 * @param builder
 *      Local notification builder instance
 */
private void applyDeleteReceiver(NotificationCompat.Builder builder) {

    if (clearReceiver == null)
        return;

    Intent deleteIntent = new Intent(context, clearReceiver).setAction(options.getIdStr())
            .putExtra(Options.EXTRA, options.toString());

    PendingIntent dpi = PendingIntent.getBroadcast(context, 0, deleteIntent, PendingIntent.FLAG_CANCEL_CURRENT);

    builder.setDeleteIntent(dpi);
}

From source file:francesco.workspace.homeapp.GcmIntentService.java

private void sendNotification(String msg) {
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    if (extras.containsKey("notification_type")) {
        NotificationCompat.Builder build = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_iconphone).setContentTitle("TapEvent - New Group!")
                .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setAutoCancel(true)
                .setContentText(msg).setLights(Color.BLUE, 300, 100).setDefaults(Notification.DEFAULT_VIBRATE);

        mNotificationManager.notify(NOTIFICATION_ID, build.build());

        return;// w  w  w.  j a v  a2  s .c  om
    }

    Intent intent = new Intent(this, Event_details_invitation.class);
    Event_App ev = new Event_App(extras.getString("event_key"), extras.getString("event_name"),
            extras.getString("event_date"), extras.getString("event_hour"), extras.getString("event_user"),
            extras.getString("event_address"), extras.getString("event_location"),
            extras.getString("event_description"));

    ev.setState("false");
    intent.putExtra("singleEvent", ev);

    Intent intent_accept = new Intent();
    Intent intent_refuse = new Intent();

    intent_accept.putExtra("singleEvent", ev);
    intent_refuse.putExtra("singleEvent", ev);
    intent_accept.setAction(ACCEPT_INTENT);
    intent_refuse.setAction(REFUSE_INTENT);

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

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_iconphone).setContentTitle("TapEvent - New Invitation!")
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setAutoCancel(true)
            .setContentText(msg)
            .addAction(R.drawable.ok_48_blue, "Accept",
                    PendingIntent.getBroadcast(this, 1234, intent_accept, PendingIntent.FLAG_CANCEL_CURRENT))
            .addAction(R.drawable.delete_64_red, "Refuse",
                    PendingIntent.getBroadcast(this, 1234, intent_refuse, PendingIntent.FLAG_CANCEL_CURRENT))
            .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE);

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

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

/**
 * Called to update/create the service's foreground Plumble notification.
 *///from  w  w w. j  av  a  2 s  . c  o  m
private Notification createNotification() {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(mService);
    builder.setContentTitle(mService.getString(R.string.app_name));
    builder.setContentText(mCustomContentText);
    builder.setSmallIcon(R.drawable.ic_stat_notify);
    builder.setPriority(NotificationCompat.PRIORITY_MIN);
    builder.setOngoing(true);

    if (mActionsShown) {
        // Add notification triggers
        Intent muteIntent = new Intent(BROADCAST_MUTE);
        Intent deafenIntent = new Intent(BROADCAST_DEAFEN);
        Intent overlayIntent = new Intent(BROADCAST_OVERLAY);

        builder.addAction(R.drawable.ic_action_microphone, mService.getString(R.string.mute),
                PendingIntent.getBroadcast(mService, 1, muteIntent, PendingIntent.FLAG_CANCEL_CURRENT));
        builder.addAction(R.drawable.ic_action_audio, mService.getString(R.string.deafen),
                PendingIntent.getBroadcast(mService, 1, deafenIntent, PendingIntent.FLAG_CANCEL_CURRENT));
        builder.addAction(R.drawable.ic_action_channels, mService.getString(R.string.overlay),
                PendingIntent.getBroadcast(mService, 2, overlayIntent, PendingIntent.FLAG_CANCEL_CURRENT));
    }

    Intent channelListIntent = new Intent(mService, PlumbleActivity.class);
    channelListIntent.putExtra(PlumbleActivity.EXTRA_DRAWER_FRAGMENT, DrawerAdapter.ITEM_SERVER);
    // FLAG_CANCEL_CURRENT ensures that the extra always gets sent.
    PendingIntent pendingIntent = PendingIntent.getActivity(mService, 0, channelListIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    builder.setContentIntent(pendingIntent);

    Notification notification = builder.build();
    mService.startForeground(NOTIFICATION_ID, notification);
    return notification;
}

From source file:com.ta.truckmap.gpstracking.GcmIntentService.java

private void startT2TIntent(String id, String type) {
    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    Intent pushIntent = startUserCreatePushIntent(id, type);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, pushIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    Notification notification = createNotificationConstraints(contentIntent, 1);
    nm.notify(TAG, (NOTIFICATION_ID), notification);

}

From source file:com.appsaur.tarucassist.AlarmReceiver.java

public void setRepeatAlarm(Context context, Calendar calendar, int ID, long RepeatTime) {
    mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    // Put Reminder ID in Intent Extra
    Intent intent = new Intent(context, AlarmReceiver.class);
    intent.putExtra(BaseActivity.EXTRA_REMINDER_ID, Integer.toString(ID));
    mPendingIntent = PendingIntent.getBroadcast(context, ID, intent, PendingIntent.FLAG_CANCEL_CURRENT);

    // Calculate notification timein
    Calendar c = Calendar.getInstance();
    long currentTime = c.getTimeInMillis();
    long diffTime = calendar.getTimeInMillis() - currentTime;

    // Start alarm using initial notification time and repeat interval time
    mAlarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + diffTime,
            RepeatTime, mPendingIntent);

    // Restart alarm if device is rebooted
    ComponentName receiver = new ComponentName(context, BootReceiver.class);
    PackageManager pm = context.getPackageManager();
    pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
            PackageManager.DONT_KILL_APP);
}

From source file:eu.inmite.apps.smsjizdenka.util.NotificationUtil.java

public static void notifyMessage(Context c, String message) {
    Intent i = new Intent(c, MainActivity.class);
    i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    i.putExtra(MainActivity.EXTRA_MESSAGE, message);
    PendingIntent contentIntent = PendingIntent.getActivity(c, NOTIFICATION_MESSAGE, i,
            PendingIntent.FLAG_CANCEL_CURRENT);
    String title = c.getString(R.string.application_name);
    String text = message;/*from   w w w  . j a v  a  2 s . c  om*/
    fireNotification(c, NOTIFICATION_VERIFY, contentIntent, title, text, null, null, title,
            R.drawable.notification_small_ready, R.drawable.notification_big_ready, null, false);
    Preferences.set(c, Preferences.MESSAGE_READ, false);
}

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

/**
 * Fgt der Notification einen onclick Handler hinzu.
 *//*  w w  w.j a  v  a2  s .c o  m*/
private NotificationCompat.Builder setClickEvent(NotificationCompat.Builder notification) {
    Intent intent = new Intent(context, ReceiverActivity.class)
            .putExtra(OPTIONS, options.getJSONObject().toString()).setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);

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

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

    return notification.setContentIntent(contentIntent);
}

From source file:com.wifi.brainbreaker.mydemo.spydroid.ui.SpydroidActivity.java

public void onStart() {
    super.onStart();

    // Lock screen
    mWakeLock.acquire();//from w w  w  . j  a v  a  2 s.  co  m

    // Did the user disabled the notification ?
    if (mApplication.notificationEnabled) {
        Intent notificationIntent = new Intent(this, SpydroidActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
        Notification notification = builder.setContentIntent(pendingIntent).setWhen(System.currentTimeMillis())
                .setTicker(getText(R.string.notification_title)).setSmallIcon(R.drawable.icon)
                .setContentTitle(getText(R.string.notification_title))
                .setContentText(getText(R.string.notification_content)).build();
        notification.flags |= Notification.FLAG_ONGOING_EVENT;
        ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(0, notification);
    } else {
        removeNotification();
    }

    bindService(new Intent(this, CustomHttpServer.class), mHttpServiceConnection, Context.BIND_AUTO_CREATE);
    bindService(new Intent(this, CustomRtspServer.class), mRtspServiceConnection, Context.BIND_AUTO_CREATE);

}

From source file:com.alexandreroman.nrelay.NmeaRelayService.java

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

    uiHandler = new Handler(Looper.getMainLooper()) {
        @Override//from  w  w  w. j  a  v  a 2s . c o m
        public void handleMessage(Message msg) {
            for (final WeakReference<NmeaRelayListener> listenerRef : listenerRefs) {
                final NmeaRelayListener listener = listenerRef.get();
                if (listener != null) {
                    try {
                        listener.onNmeaRelayContextChanged(context);
                    } catch (Exception e) {
                        Log.w(TAG, "Error in NMEA relay listener: " + listener, e);
                    }
                }
            }
        }
    };

    openMainActivityIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class),
            PendingIntent.FLAG_CANCEL_CURRENT);
    locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    powerManager = (PowerManager) getSystemService(POWER_SERVICE);
    prefs = getSharedPreferences(PREF_FILE, MODE_PRIVATE);
}