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.maryplasez.spicemeapp.MyFirebaseMessagingService.java

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

    String title = "I want to lick you till you swear allegiance to the empire";
    Intent intent = new Intent(this, ChatActivity.class);
    intent.putExtra("PUSH", title);
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
    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(R.mipmap.icon).setContentTitle(title).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.panamon.paccozz.fcm.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *//*from w ww .j  a v a  2 s  .co 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.drawable.ic_stat_ic_notification).setContentTitle("Paccozz")
            .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.mobilewrapper.base.gcm.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*from ww  w  .j  a v  a2s. co  m*/
 */
private void sendNotification(PushMessage message) {
    Intent intent = new Intent(this, SplashActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

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

    NotificationCompat.Style style = null;
    if (message.getThumb() == null || message.getThumb().equals("")) {
        style = new NotificationCompat.BigTextStyle().bigText(Html.fromHtml(message.getDescription()));
    } else {
        Bitmap remote_picture = null;
        try {
            remote_picture = BitmapFactory.decodeStream((InputStream) new URL(message.getThumb()).getContent());
        } catch (IOException e) {

        }
        style = new NotificationCompat.BigPictureStyle().bigPicture(remote_picture)
                .setSummaryText(Html.fromHtml(message.getDescription()));
    }

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_ic_notification)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
            .setTicker(message.getTitle()).setContentTitle(message.getTitle())
            .setContentText(message.getDescription()).setAutoCancel(true).setSound(defaultSoundUri)
            .setStyle(style).setContentIntent(pendingIntent);

    if (style instanceof NotificationCompat.BigPictureStyle) {
        notificationBuilder.setContentText(getString(R.string.notification_bigPictureContentText));
    }

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

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

From source file:ca.justinrichard.link.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *///from www.j  ava  2 s  .  co m
private void sendNotification(String messageBody, String linkId) {

    Intent intent;
    if (linkId.equals("")) {
        intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    } else {
        intent = new Intent(this, LinkActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.putExtra(LINK_ID, linkId);
    }

    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_link).setColor(getResources().getColor(R.color.colorPrimary))
            .setContentTitle("Link request").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.hx.hxchat.activity.HXBaseActivity.java

/**
 * ??????????? ????/* ww  w .j av  a2s.  c om*/
 * 
 * @param message
 */
protected void notifyNewMessage(EMMessage message) {
    // ????(app??demo??)
    // ?setShowNotificationInbackgroup:false(false???sdk??)
    if (!EasyUtils.isAppRunningForeground(this)) {
        return;
    }
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(getApplicationInfo().icon).setWhen(System.currentTimeMillis()).setAutoCancel(true);
    String ticker = CommonUtils.getMessageDigest(message, this);
    String st = getResources().getString(R.string.expression);
    if (message.getType() == Type.TXT)
        ticker = ticker.replaceAll("\\[.{2,3}\\]", st);
    User user = BaseApplication.getApplication().getContactList().get(message.getFrom());
    if (user == null) {
        name = message.getFrom();
    } else {
        name = user.getAvatar();
    }

    // ????
    mBuilder.setTicker(name + ": " + ticker);

    // pendingintent?2.3bug
    Intent intent = new Intent(this, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, notifiId, intent,
            PendingIntent.FLAG_ONE_SHOT);
    mBuilder.setContentIntent(pendingIntent);

    Notification notification = mBuilder.build();
    notificationManager.notify(notifiId, notification);
    notificationManager.cancel(notifiId);
}

From source file:com.app.ntuc.notifs.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*from   w ww  . j av  a2  s  .  c o  m*/
 */
private void sendNotification(String body, String title, Bundle bundle) {
    Intent intent = new Intent(this, MainActivity2_.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle();
    bigText.bigText(bundle.toString());
    bigText.setBigContentTitle(body);
    bigText.setSummaryText(title);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_ic_notification).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    notificationBuilder.setContentTitle(body).setContentText(title);

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

    notificationManager.notify(6969, notificationBuilder.build());
}

From source file:com.webonise.gardenIt.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*from   w  ww .  j a va  2  s .  co m*/
 */
private void sendNotification(String id, String type, String message) {
    Intent intent = new Intent(this, GeneralDetailsActivity.class);
    if (type.equalsIgnoreCase(getString(R.string.notification_type_issue))) {
        intent.putExtra(Constants.BUNDLE_KEY_TYPE, Constants.TYPE_ADVICE);
    } else if (type.equalsIgnoreCase(getString(R.string.notification_type_request))) {
        intent.putExtra(Constants.BUNDLE_KEY_TYPE, Constants.TYPE_SERVICE);
    }
    intent.putExtra(Constants.BUNDLE_KEY_ID, Integer.parseInt(id));
    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_notification).setLargeIcon(getBitmapDrawable())
            .setContentTitle(getString(R.string.app_name)).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.kr.zenithcompany.MyGcmListenerService.java

private void sendNotification(String message, Bitmap bitmap) {
    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);
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setPriority(NotificationCompat.PRIORITY_MAX)
            .setContentTitle(getResources().getString(R.string.app_name)).setSmallIcon(R.mipmap.icon)
            .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);
    if (bitmap != null) {
        NotificationCompat.BigPictureStyle style = new NotificationCompat.BigPictureStyle();
        style.setBigContentTitle(getString(R.string.app_name));
        style.setSummaryText(message);//from   w w  w  . j av  a 2  s  . c  om
        style.bigPicture(bitmap);
        notificationBuilder.setStyle(style);
    }

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

    notificationManager.notify(UniqueID.getRandomNumber(1000), notificationBuilder.build());
}

From source file:com.UpTopApps.OilResetPro.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *///w ww  .ja v a 2 s  . c  o m
private void sendNotification(String messageBody, String title) {
    Intent intent = new Intent(this, NotificationActivity.class);
    String text = "";
    try {

        JSONObject obj = new JSONObject(messageBody);

        text = obj.getString("text");

    } catch (JSONException e) {
        Log.d("jex", e.getMessage());
    }
    intent.putExtra("body", text);
    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_stat_ic_notification).setContentTitle(title).setContentText(text)
            .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.mobirix.battlefieldcommander.activity.BillingNativeActivity.java

public void sendNotification(int id, String title, String message) {
    Intent intent = new Intent(this, BillingNativeActivity.class);
    //intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Resources res = this.getResources();
    int icon = res.getIdentifier("ic_stat_ic_notification", "drawable", this.getPackageName());

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this).setSmallIcon(icon) //todo
            .setContentTitle(title).setContentText(message).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

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

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