Example usage for android.app PendingIntent FLAG_ONE_SHOT

List of usage examples for android.app PendingIntent FLAG_ONE_SHOT

Introduction

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

Prototype

int FLAG_ONE_SHOT

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

Click Source Link

Document

Flag indicating that this PendingIntent can be used only once.

Usage

From source file:com.sender.team.sender.gcm.MyGcmListenerService.java

private void sendNotificationConfirm() {
    Intent intent = new Intent(this, SplashActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher).setTicker("SENDER").setContentTitle("SENDER")
            .setContentText("? ? ?").setAutoCancel(true)
            .setDefaults(NotificationCompat.DEFAULT_ALL).setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}

From source file:com.alivenet.dmvtaxi.FcmUtil.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./* w  w w .  j  a v  a  2  s. com*/
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void sendNotification(String message) {
    SharedPreference sharedPreference = new SharedPreference();

    if (splitnotifiaction_flag) {
        intent = new Intent(this, AcceptNotificationUIwork.class);
        if (flag == true) {
            intent.putExtra("ridedriverInfo", MyApplication.rideDriverComplete);
            intent.putExtra("flag", flag);
        }
    } else {

        intent = new Intent(this, DeashboardActivity.class);
        if (flag == true) {
            intent.putExtra("ridedriverInfo", MyApplication.rideDriverComplete);
            intent.putExtra("flag", flag);
        }
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
                PendingIntent.FLAG_ONE_SHOT);
        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("Notification").setContentText(message)
                .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);

        NotificationManager notificationManager = (NotificationManager) getSystemService(
                Context.NOTIFICATION_SERVICE);
        notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());

    }
}

From source file:com.unfc.choicecustomercare.gcmservices.MyGcmListenerService.java

private void sendNotificationForChargedNurse(String message) {

    Intent intent = new Intent(this, MainActivity.class);
    intent.setAction("chargedNurse");
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

    Intent intentAccept = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingAccept = PendingIntent.getActivity(this, 1, intentAccept, PendingIntent.FLAG_ONE_SHOT);
    ////from w w w  .j a  v a2s  .c o  m
    Intent intentDecline = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingDecline = PendingIntent.getActivity(this, 2, intentDecline,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher).setContentTitle(getString(R.string.app_name))
            .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent).setAutoCancel(true);

    notificationBuilder.getNotification().flags |= Notification.FLAG_AUTO_CANCEL;
    notificationBuilder.setAutoCancel(true);

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    notificationManager.notify((int) new Date().getTime(), notificationBuilder.build());

}

From source file:com.android.deskclock.timer.TimerReceiver.java

private void updateNextTimesup(Context context) {
    TimerObj t = getNextRunningTimer(mTimers, false, Utils.getTimeNow());
    long nextTimesup = (t == null) ? -1 : t.getTimesupTime();
    int timerId = (t == null) ? -1 : t.mTimerId;

    Intent intent = new Intent();
    intent.setAction(Timers.TIMES_UP);/*from w  w  w  . j  a  va  2s .c  o m*/
    intent.setClass(context, TimerReceiver.class);
    // Time-critical, should be foreground
    intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    if (!mTimers.isEmpty()) {
        intent.putExtra(Timers.TIMER_INTENT_EXTRA, timerId);
    }
    AlarmManager mngr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    PendingIntent p = PendingIntent.getBroadcast(context, 0, intent,
            PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT);
    if (t != null) {
        if (Utils.isKitKatOrLater()) {
            mngr.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, nextTimesup, p);
        } else {
            mngr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, nextTimesup, p);
        }
        if (Timers.LOGGING) {
            Log.d(TAG, "Setting times up to " + nextTimesup);
        }
    } else {
        // if no timer is found Pending Intents should be canceled
        // to keep the internal state consistent with the UI
        mngr.cancel(p);
        p.cancel();
        if (Timers.LOGGING) {
            Log.v(TAG, "no next times up");
        }
    }
}

From source file:com.zaparound.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *//*from ww w . ja  va2  s .  co  m*/
private void sendAcceptNotification(String messagetitle, String messageBody) {
    Intent intent = new Intent(this, LandingActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.addFlags(
            Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra("CHATTAB_POSITION", 2);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
    Notification notification = mBuilder.setSmallIcon(R.drawable.applogo).setTicker(messagetitle).setWhen(0)
            .setAutoCancel(true).setContentTitle(messagetitle)
            //.setNumber(++count)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(messageBody))
            //.setSubText("\n "+count+" new messages\n")
            .setContentIntent(pendingIntent)
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
            .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.applogo))
            .setContentText(messageBody).build();

    NotificationManager notificationManager = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, notification);
}

From source file:com.piggeh.palmettoscholars.services.MyFirebaseMessagingService.java

public void notifyNewsletter(String title, String URL) {
    Uri webpage = Uri.parse(URL);
    Intent contentIntent = new Intent(Intent.ACTION_VIEW, webpage);
    PendingIntent contentPendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, contentIntent,
            PendingIntent.FLAG_ONE_SHOT);

    Intent settingsIntent = new Intent(this, SettingsActivity.class);
    settingsIntent.putExtra("navigation_page", MainActivity.PAGE_SETTINGS);
    settingsIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent settingsPendingIntent = PendingIntent.getActivity(this, 3 /* Request code */, settingsIntent,
            PendingIntent.FLAG_ONE_SHOT);

    NotificationCompat.BigTextStyle notifStyle = new NotificationCompat.BigTextStyle();
    notifStyle.bigText(title);//  w ww .  j a  va2 s  . co m
    notifStyle.setBigContentTitle(getString(R.string.notif_newsletter_title));

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.notification_icon_nodpi)
            .setContentTitle(getString(R.string.notif_newsletter_title)).setContentText(title)
            .setAutoCancel(true).setSound(defaultSoundUri)
            .setColor(ContextCompat.getColor(this, R.color.colorPrimary)).setContentIntent(contentPendingIntent)
            .setStyle(notifStyle).addAction(R.drawable.ic_notifications_off,
                    getString(R.string.notif_action_options), settingsPendingIntent);

    // Get an instance of the NotificationManager service
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);

    // Build the notification and issues it with notification manager.
    notificationManager.notify(NOTIFICATION_ID_NEWSLETTER, notificationBuilder.build());
}

From source file:io.github.hidroh.materialistic.data.SyncDelegate.java

private PendingIntent getItemActivity(String itemId) {
    return PendingIntent.getActivity(mContext, 0,
            new Intent(Intent.ACTION_VIEW).setData(AppUtils.createItemUri(itemId))
                    .putExtra(ItemActivity.EXTRA_CACHE_MODE, ItemManager.MODE_CACHE)
                    .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK),
            PendingIntent.FLAG_ONE_SHOT);
}

From source file:com.embeddedlog.LightUpDroid.timer.TimerReceiver.java

private void showCollapsedNotificationWithNext(final Context context, String title, String text,
        Long nextBroadcastTime) {
    Intent activityIntent = new Intent(context, DeskClock.class);
    activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    activityIntent.putExtra(DeskClock.SELECT_TAB_INTENT_EXTRA, DeskClock.TIMER_TAB_INDEX);
    PendingIntent pendingActivityIntent = PendingIntent.getActivity(context, 0, activityIntent,
            PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT);
    showCollapsedNotification(context, title, text, Notification.PRIORITY_HIGH, pendingActivityIntent,
            IN_USE_NOTIFICATION_ID, false);

    if (nextBroadcastTime == null) {
        return;/* w  w  w.  j a  va  2 s  .c om*/
    }
    Intent nextBroadcast = new Intent();
    nextBroadcast.setAction(Timers.NOTIF_IN_USE_SHOW);
    PendingIntent pendingNextBroadcast = PendingIntent.getBroadcast(context, 0, nextBroadcast, 0);
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    if (Utils.isKitKatOrLater()) {
        alarmManager.setExact(AlarmManager.ELAPSED_REALTIME, nextBroadcastTime, pendingNextBroadcast);
    } else {
        alarmManager.set(AlarmManager.ELAPSED_REALTIME, nextBroadcastTime, pendingNextBroadcast);
    }
}

From source file:com.renjunzheng.vendingmachine.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.//w ww .java 2 s . c  om
 */
private void sendNotification(String message) {
    Intent intent = new Intent(this, VMSelection.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.icon_w).setContentTitle("Ultimate Vending Machine").setContentText(message)
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.icon))
            .setColor(getColor(R.color.notification_color));

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}

From source file:com.zaparound.MyFirebaseMessagingService.java

/**
 * Create and show a Inmylocation Notification.
 *
 * @param messageBody FCM message body received.
 *///from  w  w  w  .ja  v  a2  s  .  co  m
private void sendNotificationInmylocation(String messagetitle, String messageBody) {
    Intent intent = new Intent(this, LandingActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.addFlags(
            Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra("CHATTAB_POSITION", 3);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
    Notification notification = mBuilder.setSmallIcon(R.drawable.applogo).setTicker(messagetitle).setWhen(0)
            .setAutoCancel(true).setContentTitle(messagetitle)
            //.setNumber(++count)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(messageBody))
            //.setSubText("\n "+count+" new messages\n")
            .setContentIntent(pendingIntent)
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
            .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.applogo))
            .setContentText(messageBody).build();

    NotificationManager notificationManager = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, notification);
}