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:kr.ds.myfoodpdx.MyGcmListenerService.java

private void sendNotification(String message, Bitmap bitmap) {
    Intent intent = new Intent(this, IntroActivity.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);
    boolean isvibrate = SharedPreference.getBooleanSharedPreference(getApplicationContext(), "isvibrate");
    NotificationCompat.Builder notificationBuilder;
    if (isvibrate) {
        notificationBuilder = new NotificationCompat.Builder(this)
                .setContentTitle(getResources().getString(R.string.app_name)).setSmallIcon(R.mipmap.icon)
                .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri)
                .setPriority(Notification.PRIORITY_MAX).setContentIntent(pendingIntent);
    } else {//from  w  w w  .  j  a  v  a 2  s  .c  o m
        notificationBuilder = new NotificationCompat.Builder(this)
                .setContentTitle(getResources().getString(R.string.app_name)).setSmallIcon(R.mipmap.icon)
                .setContentText(message).setAutoCancel(true).setVibrate(new long[] { 0 })
                .setPriority(Notification.PRIORITY_MAX).setContentIntent(pendingIntent);
    }
    if (bitmap != null) {
        NotificationCompat.BigPictureStyle style = new NotificationCompat.BigPictureStyle();
        style.setBigContentTitle(getString(R.string.app_name));
        style.setSummaryText(message);
        style.bigPicture(bitmap);
        notificationBuilder.setStyle(style);
    }

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

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

From source file:kr.ds.travel.MyGcmListenerService.java

private void sendCommunitySubNotification(String message, String uid) {
    Intent intent = new Intent(this, IntroActivity.class);
    Uri uri = Uri.parse("travel://details?type=community_sub&uid=" + uid);
    intent.setAction(Intent.ACTION_VIEW);
    intent.setData(uri);//from   w  w w.  j a v a  2s . co  m
    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;
    if (isvibrate) {
        notificationBuilder = new NotificationCompat.Builder(this)
                .setContentTitle(getResources().getString(R.string.app_name)).setSmallIcon(R.mipmap.push_icon)
                .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri)
                .setContentIntent(pendingIntent);
    } else {
        notificationBuilder = new NotificationCompat.Builder(this)
                .setContentTitle(getResources().getString(R.string.app_name)).setSmallIcon(R.mipmap.push_icon)
                .setContentText(message).setAutoCancel(true).setVibrate(new long[] { 0 })
                .setContentIntent(pendingIntent);
    }
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

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

From source file:com.bangalore.barcamp.BCBUtils.java

public static PendingIntent createPendingIntentForID(Context context, String id, int slot, int session) {
    Intent intent = new Intent(context, SessionAlarmIntentService.class);
    intent.putExtra(SessionAlarmIntentService.SESSION_ID, id);
    intent.putExtra(SessionAlarmIntentService.EXTRA_SLOT_POS, slot);
    intent.putExtra(SessionAlarmIntentService.EXTRA_SESSION_POSITION, session);
    int idInt = Integer.parseInt(id);
    PendingIntent pendingIntent = PendingIntent.getService(context, idInt, intent, PendingIntent.FLAG_ONE_SHOT);
    return pendingIntent;
}

From source file:com.bigbug.android.pp.gcm.GCMIntentService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.//from  w ww  .j  a v  a2 s.  c  o m
 */
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.drawable.ic_stat_notification).setContentTitle("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.readystatesoftware.chuck.internal.support.NotificationHelper.java

@NonNull
private NotificationCompat.Action getClearAction() {
    CharSequence clearTitle = context.getString(R.string.chuck_clear);
    Intent deleteIntent = new Intent(context, ClearTransactionsService.class);
    PendingIntent intent = PendingIntent.getService(context, 11, deleteIntent, PendingIntent.FLAG_ONE_SHOT);
    return new NotificationCompat.Action(R.drawable.chuck_ic_delete_white_24dp, clearTitle, intent);
}

From source file:com.preguardia.app.notification.MyGcmListenerService.java

private void showConsultationClosedNotification(String title, String message, String consultationId) {
    // Prepare intent which is triggered if the notification is selected
    Intent intent = new Intent(this, ConsultationDetailsActivity.class);

    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    intent.putExtra(Constants.EXTRA_CONSULTATION_ID, consultationId);

    PendingIntent pendingIntent = PendingIntent.getActivity(this, Constants.PATIENT_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_logo).setContentTitle(title).setContentText(message)
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);

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

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

From source file:com.linute.linute.API.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param data GCM Bundle received./*from   w w w.  j  a  v  a  2  s.co m*/
 */
private void sendNotification(Bundle data, String action) {

    Intent intent = buildIntent(data, action);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), intent,
            PendingIntent.FLAG_ONE_SHOT);

    //Log.d(TAG, data.toString());

    String message = data.getString("message");

    //int type = gettNotificationType(data.getString("action"));
    //String name = data.getString("ownerFullName");
    boolean isAnon = "1".equals(data.getString("privacy"));
    String profileImage = null;
    switch (action) {
    case "messager":
        try {
            JSONObject image = new JSONObject(data.getString("roomProfileImage"));
            profileImage = image.getString("original");
        } catch (JSONException | NullPointerException e) {
        }
        break;
    default:
        profileImage = data.getString("ownerProfileImage");
        profileImage = (isAnon ? Utils.getAnonImageUrl(String.valueOf(profileImage))
                : Utils.getImageUrlOfUser(String.valueOf(profileImage)));
    }

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    ChatRoom chatRoom = (ChatRoom) intent.getParcelableExtra("chatRoom");
    String title = chatRoom != null ? chatRoom.getRoomName() : "Tapt";
    final NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_untitled_4_01).setColor(Color.BLACK).setContentTitle(title)
            .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent).setStyle(new NotificationCompat.BigTextStyle().bigText(message));
    if (profileImage != null) {
        File image = null;
        try {
            image = Glide.with(this).load(profileImage).downloadOnly(256, 256).get();
        } catch (InterruptedException | ExecutionException e) {
            e.printStackTrace();
        }
        if (image != null) {
            /*ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
            ActivityManager.MemoryInfo info = new ActivityManager.MemoryInfo();
            manager.getMemoryInfo(info);*/

            notificationBuilder.setLargeIcon(getCircleBitmap(image));

        }
    }

    BigInteger notificationId;

    Object ownerId = data.get("room");
    Object eventId = data.get("event");
    if (eventId != null) {
        notificationId = new BigInteger(String.valueOf(eventId), 16);
    } else if (ownerId != null) {
        notificationId = new BigInteger(String.valueOf(ownerId), 16);
    } else {
        notificationId = BigInteger.ZERO;
    }

    final int notifId = notificationId.intValue();
    Notification notifications = notificationBuilder.build();
    NotificationManagerCompat.from(this).notify(notificationId.intValue(), notifications);
}

From source file:com.begentgroup.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).setTicker("GCM Message").setContentTitle("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.sumang.chatdemo.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *///from  ww w  .  jav  a  2s .c o  m
private void sendNotification(String title, 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).setGroup("ABC")
            .setGroupSummary(true).setSmallIcon(R.drawable.messenger_bubble_small_white)
            .setColor(getResources().getColor(R.color.colorAccent)).setContentTitle(title)
            .setContentText(messageBody).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(getApplicationContext());

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

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

private void sendNotifications(String messageBody) {
    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);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("KPMG").setContentText(messageBody)
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);

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

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