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.unfc.choicecustomercare.gcmservices.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM
 * message.//w ww.j a  v a  2 s.  c o m
 *
 * @param message GCM message received.
 */
private void sendNotification(String message) {

    Intent intent = new Intent(this, MainActivity.class);
    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.setAction("accept");
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingAccept = PendingIntent.getActivity(this, 1, intentAccept, PendingIntent.FLAG_ONE_SHOT);
    //
    Intent intentDecline = new Intent(this, MainActivity.class);
    intent.setAction("decline");
    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(false)
            .addAction(R.drawable.accept_ico, "Accept", pendingAccept)
            .addAction(R.drawable.decline_ico, "Decline", pendingDecline);
    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.example.notification.gcm.GcmIntentService.java

private void sendNotification(String msg) {
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    // get a resource's Uri
    String soundPath = "android.resource://" + getPackageName() + "/" + R.raw.sound;
    Uri soundURI = Uri.parse(soundPath);

    try {/*  w w  w.j  a  v  a  2s .co m*/

        Intent ourIntent = new Intent(GcmIntentService.this, Message1.class);
        ourIntent.putExtra("GCM", body);
        ourIntent.putExtra("FROM", notifier);
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, ourIntent,
                PendingIntent.FLAG_ONE_SHOT);

        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.a3)
                .setContentTitle("GCM Notification").setAutoCancel(true)
                .setVibrate(new long[] { 1000, 1000, 1000, 1000 }).setSound(soundURI)
                .setWhen(System.currentTimeMillis())
                .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg);
        mBuilder.setContentIntent(contentIntent);
        // mBuilder
        mNotificationManager.notify(0, mBuilder.build());

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.handshake.notifications.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *///from ww w.  ja  v a2s.  c  o  m
private void sendNotification(final Bundle data, long userId, boolean isContact) {
    Intent intent;
    if (userId == 0) {
        intent = new Intent(this, MainActivity.class);
    } else if (isContact) {
        intent = new Intent(this, ContactUserProfileActivity.class);
    } else {
        intent = new Intent(this, GenericUserProfileActivity.class);
    }
    intent.putExtra("userId", userId);
    intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
    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.ic_stat_ic_notification).setContentTitle("Handshake")
            .setContentText(data.getString("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.hmlee.chat.chatclient.fcm.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *//*from   w ww .  ja v  a  2 s .  c  o m*/
private void sendNotification(String messageBody) {
    Intent intent = new Intent(this, MainActivity.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.mipmap.contact).setContentTitle("FCM Message").setContentText(messageBody)
            .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.example.dhaejong.acp2.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*from   w  w w . ja v  a 2s  . c om*/
 */
private void sendNotification(String message, String title) {
    Intent intent = new Intent(this, Main2Activity.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.ic_stat_ic_notification).setContentTitle(title).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.evandroid.musica.services.BatchDownloaderService.java

private void updateProgress() {
    NotificationManager manager = ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE));
    if (count < total) {
        NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this);
        notifBuilder.setSmallIcon(android.R.drawable.stat_sys_download)
                .setContentTitle(getString(R.string.app_name))
                .setContentText(String.format(getString(R.string.dl_progress), count, total))
                .setProgress(total, count, false).setShowWhen(false);
        Notification notif = notifBuilder.build();
        notif.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
        if (count == 0)
            startForeground(1, notif);// www .  j  a v a2  s  .  co  m
        else
            manager.notify(1, notif);
    } else {
        stopForeground(true);
        Intent refreshIntent = new Intent("com.geecko.QuickLyric.updateDBList");
        PendingIntent pendingIntent = PendingIntent.getActivity(getBaseContext(), 4, refreshIntent,
                PendingIntent.FLAG_ONE_SHOT);
        String text = getResources().getQuantityString(R.plurals.dl_finished_desc, successCount, successCount);
        NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this);
        notifBuilder.setSmallIcon(android.R.drawable.stat_sys_download_done);
        notifBuilder.setContentIntent(pendingIntent);
        notifBuilder.setContentTitle(getString(R.string.dl_finished));
        notifBuilder.setContentText(text);
        Notification notif = notifBuilder.build();
        notif.flags |= Notification.FLAG_AUTO_CANCEL;
        manager.notify(1, notif);
        stopSelf();
    }
}

From source file:com.hidezo.app.buyer.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *//*from  www  . j a v  a 2 s .  c  om*/
private void sendNotification(final String messageBody, final int type_flag) {

    //        Log.d(TAG, messageBody);
    final AppGlobals globals = (AppGlobals) this.getApplication();

    // ??Intent?
    final Intent intent;
    // ?
    if (globals.getLoginState()) {
        // 
        switch (type_flag) {
        case 1:
            // 
            intent = new Intent(this, ActivityOrderes.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            break;
        default:
            // ?
            intent = new Intent(this, ActivitySuppliers.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            break;
        }
    } else {
        // ?
        intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    }
    final PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /*Request code*/, intent,
            PendingIntent.FLAG_ONE_SHOT);

    // 
    final Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    final NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_notification).setContentTitle(getString(R.string.app_name))
            .setContentText(messageBody).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    //        /* Add Big View Specific Configuration */
    //        final NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
    //
    //        // Sets a title for the Inbox style big view
    //        inboxStyle.setBigContentTitle(messageBody);
    //
    //        inboxStyle.addLine("");
    //
    //        notificationBuilder.setStyle(inboxStyle);
    // ------------------------------------------

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

}

From source file:com.shoppingspree.shoppingspree.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *//*from  w ww.  j a  va2s . c o m*/
private void sendNotification(String messageBody) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    String channelId = getString(R.string.default_notification_channel_id);
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, channelId)
            .setSmallIcon(R.drawable.ic_stat_ic_notification).setContentTitle("Buy Through Shopping Spree")
            .setContentText(messageBody).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

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

    // Since android Oreo notification channel is needed.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel channel = new NotificationChannel(channelId, "Channel human readable title",
                NotificationManager.IMPORTANCE_DEFAULT);
        notificationManager.createNotificationChannel(channel);
    }

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

From source file:com.karbide.bluoh.notification.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *///from  www .  j  a  va  2s  .  c  o m

private void sendNotification(String messageBody, Bitmap image, String TrueOrFalse) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra("AnotherActivity", TrueOrFalse);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 1 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            //                .setLargeIcon(image)/*Notification icon image*/
            .setSmallIcon(R.mipmap.ic_launcher).setContentTitle(messageBody)
            .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(image))/*Notification with Image*/
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);

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

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

From source file:com.futureplatforms.kirin.extensions.localnotifications.LocalNotificationsBackend.java

public PendingIntent createPendingIntentForSchedule(String idString) {
    Intent intent = createIntentForSchedule(idString);
    return PendingIntent.getBroadcast(mContext, C.REQUEST_CODE_LOCALNOTIFICATION, intent,
            PendingIntent.FLAG_ONE_SHOT);
}