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:kpits.notif_msoc.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 */// w w w  . j a  v a2 s .  c om
private void sendNotification(String messageBody, String title) {
    Intent intent = new Intent(this, PertanyaanActivity.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(messageBody)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(title + "\n" + 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.jkgan.pmot.service.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  2 s .co  m*/
 */
private void sendNotification(final String message, final String title, String id) {

    String url = MyApplication.getApiUrl() + "/promotions/" + id + "?token="
            + MyApplication.getUser().getToken();
    final Promotion[] promotion = { null };

    final OkHttpClient client = new OkHttpClient();

    final Request request = new Request.Builder().url(url).build();

    //        new Thread(new Runnable() {
    //            @Override
    //            public void run() {
    Response response = null;
    try {
        response = client.newCall(request).execute();
        JSONObject jsnObj2 = new JSONObject(response.body().string());

        promotion[0] = new Promotion(jsnObj2.optString("pName"), jsnObj2.optString("description"),
                jsnObj2.optString("id"),
                jsnObj2.getJSONObject("image").getJSONObject("medium").optString("url"),
                jsnObj2.getJSONObject("image").getJSONObject("small").optString("url"),
                jsnObj2.optString("term_and_condition"), jsnObj2.optString("name"),
                jsnObj2.optString("address"), jsnObj2.optString("sId"), getDate(jsnObj2.optString("starts_at")),
                getDate(jsnObj2.optString("expires_at")), jsnObj2.optString("phone"));

        Intent intent = new Intent(getApplicationContext(), PromotionActivity.class);
        intent.putExtra("NAME", promotion[0].getName());
        intent.putExtra("SHOP_ID", promotion[0].getId());
        intent.putExtra("IMAGE", promotion[0].getImage());
        intent.putExtra("DESCRIPTION", promotion[0].getDescription());
        intent.putExtra("TNC", promotion[0].getTnc());
        intent.putExtra("SHOP_NAME", promotion[0].getShop().getName());
        intent.putExtra("ADDRESS", promotion[0].getShop().getAddress());
        intent.putExtra("START", promotion[0].getStarts_at());
        intent.putExtra("EXPIRE", promotion[0].getExpires_at());
        intent.putExtra("PHONE", promotion[0].getShop().getPhone());
        intent.putExtra("SUBSCRIBED", true);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0 /* Request code */,
                intent, PendingIntent.FLAG_ONE_SHOT);

        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        if (numMessages >= 1) {
            notificationTitle += (", " + title);

            notificationBuilder = new NotificationCompat.Builder(getApplicationContext())
                    .setSmallIcon(R.mipmap.ic_launcher).setContentTitle((numMessages + 1) + " new promotions")
                    .setContentText(notificationTitle).setAutoCancel(true).setSound(defaultSoundUri)
                    .setContentIntent(pendingIntent);
            numMessages = 0;

            notificationBuilder.setContentText(message).setNumber(++numMessages);

        } else {
            notificationBuilder = new NotificationCompat.Builder(getApplicationContext())
                    .setSmallIcon(R.mipmap.ic_launcher).setContentTitle(title).setContentText(message)
                    .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);

            notificationTitle = title;
            numMessages++;
            //            notificationBuilder.setContentText(message)
            //                    .setNumber(++numMessages);
        }

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

        // On gnre un nombre alatoire pour pouvoir afficher plusieurs notifications
        notificationManager.notify(notifyID, notificationBuilder.build());
    } catch (IOException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:com.example.tacademy.miniproject.gcm.MyGcmListenerService.java

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 /* 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("GCM Message").setTicker("GCM Message")
            .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.app.infideap.postingapp.service.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *//*from w  w w  . jav a 2  s.  c  o  m*/
private void sendNotification(RemoteMessage remoteMessage) {
    //        Toast.makeText(getApplication(), "Received", Toast.LENGTH_SHORT).show();
    Notification notification = null;
    if (remoteMessage.getData() != null)
        notification = saveData(remoteMessage);
    else if (remoteMessage.getNotification() != null)
        notification = save(remoteMessage);

    if (notification == null)
        return;

    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.ic_launcher).setContentTitle(notification.title)
            .setContentText(notification.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.hukum.app_framework.application.gcm.controller.AppGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param intent GCM message received.//from   w w w.  j  ava 2s .  c om
 */
private void sendNotification(Intent intent, String message) {
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(getNotificationIcon()).setContentTitle(getString(R.string.app_name))
            .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri)
            .setPriority(Notification.PRIORITY_HIGH)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(message)).setContentIntent(pendingIntent);
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        notificationBuilder.setColor(getResources().getColor(R.color.color_accent));
    }
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, notificationBuilder.build());
}

From source file:com.pdmanager.firebase.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *//*w  ww .  j  a va 2  s .  c  o  m*/
private void sendNotification(String messageBody) {
    Intent intent = new Intent(this, ClinicianActivity.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("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.bluros.updater.service.UpdateCheckService.java

private void recordAvailableUpdates(LinkedList<UpdateInfo> availableUpdates, Intent finishedIntent) {

    if (availableUpdates == null) {
        sendBroadcast(finishedIntent);//from   w w w  .ja v a  2s  .com
        return;
    }

    // Store the last update check time and ensure boot check completed is true
    Date d = new Date();
    PreferenceManager.getDefaultSharedPreferences(UpdateCheckService.this).edit()
            .putLong(Constants.LAST_UPDATE_CHECK_PREF, d.getTime())
            .putBoolean(Constants.BOOT_CHECK_COMPLETED, true).apply();

    int realUpdateCount = finishedIntent.getIntExtra(EXTRA_REAL_UPDATE_COUNT, 0);
    UpdateApplication app = (UpdateApplication) getApplicationContext();

    // Write to log
    Log.i(TAG, "The update check successfully completed at " + d + " and found " + availableUpdates.size()
            + " updates (" + realUpdateCount + " newer than installed)");

    if (realUpdateCount != 0 && !app.isMainActivityActive()) {
        // There are updates available
        // The notification should launch the main app
        Intent i = new Intent(this, UpdatesSettings.class);
        i.putExtra(UpdatesSettings.EXTRA_UPDATE_LIST_UPDATED, true);
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_ONE_SHOT);

        Resources res = getResources();
        String text = res.getQuantityString(R.plurals.not_new_updates_found_body, realUpdateCount,
                realUpdateCount);

        // Get the notification ready
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_system_update).setWhen(System.currentTimeMillis())
                .setTicker(res.getString(R.string.not_new_updates_found_ticker))
                .setContentTitle(res.getString(R.string.not_new_updates_found_title)).setContentText(text)
                .setContentIntent(contentIntent).setLocalOnly(true).setAutoCancel(true);

        LinkedList<UpdateInfo> realUpdates = new LinkedList<UpdateInfo>();
        for (UpdateInfo ui : availableUpdates) {
            if (ui.isNewerThanInstalled()) {
                realUpdates.add(ui);
            }
        }

        Collections.sort(realUpdates, new Comparator<UpdateInfo>() {
            @Override
            public int compare(UpdateInfo lhs, UpdateInfo rhs) {
                /* sort by date descending */
                long lhsDate = lhs.getDate();
                long rhsDate = rhs.getDate();
                if (lhsDate == rhsDate) {
                    return 0;
                }
                return lhsDate < rhsDate ? 1 : -1;
            }
        });

        NotificationCompat.InboxStyle inbox = new NotificationCompat.InboxStyle(builder)
                .setBigContentTitle(text);
        int added = 0, count = realUpdates.size();

        for (UpdateInfo ui : realUpdates) {
            if (added < EXPANDED_NOTIF_UPDATE_COUNT) {
                inbox.addLine(ui.getName());
                added++;
            }
        }
        if (added != count) {
            inbox.setSummaryText(
                    res.getQuantityString(R.plurals.not_additional_count, count - added, count - added));
        }
        builder.setStyle(inbox);
        builder.setNumber(availableUpdates.size());

        if (count == 1) {
            i = new Intent(this, DownloadReceiver.class);
            i.setAction(DownloadReceiver.ACTION_START_DOWNLOAD);
            i.putExtra(DownloadReceiver.EXTRA_UPDATE_INFO, (Parcelable) realUpdates.getFirst());
            PendingIntent downloadIntent = PendingIntent.getBroadcast(this, 0, i,
                    PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT);

            builder.addAction(R.drawable.ic_tab_download, res.getString(R.string.not_action_download),
                    downloadIntent);
        }

        // Trigger the notification
        NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        nm.notify(R.string.not_new_updates_found_title, builder.build());
    }

    sendBroadcast(finishedIntent);
}

From source file:com.godowondev.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*from   w  w  w  . j  a  va 2s  .c om*/
 */
private void sendNotification(String message) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    if (message.startsWith("[ADDITIONAL_MAIL_RING")) {
        intent.putExtra("navi_type", "additional_mail");
        //defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
        defaultSoundUri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.wakeup);

        //sendSMS("01099989584", message);
    } else {
        intent.putExtra("navi_type", "reservation_error");
    }

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.logo).setContentTitle("?? PUSH ").setContentText(message)
            .setAutoCancel(true).setContentIntent(pendingIntent);

    if (message.startsWith("[ADDITIONAL_MAIL_SMS")) {
        //notificationBuilder.setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 });
        notificationBuilder.setSound(defaultSoundUri);
    } else if (message.startsWith("[ADDITIONAL_MAIL_RING")) {
        AudioManager audiomanager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        audiomanager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
        notificationBuilder.setSound(defaultSoundUri);
    }

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

    Notification note = notificationBuilder.build();

    if ((message.startsWith("[ADDITIONAL_MAIL_SMS_KYS]") || message.startsWith("[ADDITIONAL_MAIL_SMS_ALL]")
            || message.startsWith("[ADDITIONAL_MAIL_RING_KYS]")
            || message.startsWith("[ADDITIONAL_MAIL_RING_ALL]"))
            && getResources().getString(R.string.member_name).equals("?")) {
        notificationManager.notify(0 /* ID of notification */, note);
    }

    if ((message.startsWith("[ADDITIONAL_MAIL_SMS_KDW]") || message.startsWith("[ADDITIONAL_MAIL_SMS_ALL]")
            || message.startsWith("[ADDITIONAL_MAIL_RING_KDW]")
            || message.startsWith("[ADDITIONAL_MAIL_RING_ALL]"))
            && getResources().getString(R.string.member_name).equals("")) {
        notificationManager.notify(0 /* ID of notification */, note);
    }
    //note.flags = Notification.FLAG_INSISTENT; // ?  ? 
    //notificationManager.notify(0 /* ID of notification */, note);
}

From source file:com.fast.van.cloudmessaging.MyGcmListenerService.java

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

    /*Intent intent;
    if(notificationType!=null&&notificationType.equals("DRIVER_ASSIGNED")){
        intent=new Intent(this,ActivityNewRequest.class);
    }else{
            
    }*/

    if (BaseActivity.isForeGround()) {
        Intent intent = new Intent(this, ActivityNewRequest.class);
        intent.putExtra("message", message);
        intent.putExtra("orderId", orderId);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
        return;
    }

    BaseUtils.removeNotification(this);
    CommonData.saveNotificationData(this, orderId, message);
    Intent intent = new Intent(this, ActivitySplash.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra("message", message);
    intent.putExtra("orderId", orderId);
    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.notification).setContentTitle(getString(R.string.app_name))
            .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

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

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

From source file:android.example.com.squawker.fcm.SquawkFirebaseMessageService.java

/**
 * Create and show a simple notification containing the received FCM message
 *
 * @param data Map which has the message data in it
 *///from ww w  . ja  v a  2 s .  c  o m
private void sendNotification(Map<String, String> data) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    // Create the pending intent to launch the activity
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    String author = data.get(JSON_KEY_AUTHOR);
    String message = data.get(JSON_KEY_MESSAGE);

    // If the message is longer than the max number of characters we want in our
    // notification, truncate it and add the unicode character for ellipsis
    if (message.length() > NOTIFICATION_MAX_CHARACTERS) {
        message = message.substring(0, NOTIFICATION_MAX_CHARACTERS) + "\u2026";
    }

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_duck)
            .setContentTitle(String.format(getString(R.string.notification_message), author))
            .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

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

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