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.barelabor.barelabor.gcm.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.//from w ww. j ava 2s .c  om
 */
private void sendNotification(String repairArrayString, String highCostArrayString,
        String averageCostArrayString, String lowCostArrayString, String lowPrice, String highPrice,
        String avgPrice) {

    //        String lowPrice = "0", highPrice = "0", avgPrice = "0";
    //        try {
    //            JSONArray data = new JSONArray(message);
    //            lowPrice = data.getJSONObject(0).getString("lowCost");
    //            avgPrice = data.getJSONObject(0).getString("averageCost");
    //            highPrice = data.getJSONObject(0).getString("highCost");
    //        } catch (JSONException e) {
    //            e.printStackTrace();
    //        }

    Intent intent = new Intent(this, MenuActivity.class);
    intent.putExtra("low_price", lowPrice);
    intent.putExtra("high_price", highPrice);
    intent.putExtra("avg_price", avgPrice);
    intent.putExtra("repairArrayString", repairArrayString);
    intent.putExtra("highCostArrayString", highCostArrayString);
    intent.putExtra("averageCostArrayString", averageCostArrayString);
    intent.putExtra("lowCostArrayString", lowCostArrayString);
    intent.putExtra("notification", true);

    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("BareLabor")
            .setContentText("The pricing for your printed estimate has arrived").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.mb.kids_mind.GcmIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();/* w  w  w  .j a  v a2 s  .c  o  m*/
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
    // The getMessageType() intent parameter must be the intent you received
    // in your BroadcastReceiver.
    String messageType = gcm.getMessageType(intent);
    Log.v(TAG, "messageType" + messageType);
    if (!extras.isEmpty()) { // has effect of unparcelling Bundle
        /*
         * Filter messages based on message type. Since it is likely that GCM will be
         * extended in the future with new message types, just ignore any message types you're
         * not interested in, or that you don't recognize.
         */
        if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
            sendNotification("Send error: " + extras.toString());
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
            sendNotification("Deleted messages on server: " + extras.toString());
            // If it's a regular GCM message, do some work.
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
            // This loop represents the service doing some work.
            for (int i = 0; i < 5; i++) {
                Log.i(TAG, "Working... " + (i + 1) + "/5 @ " + SystemClock.elapsedRealtime());
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                }
            }
            Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());
            // Post notification of received message.
            sendNotification("Received: " + extras.toString());

            if (PushWakeLock.ScreenOn(this)) {
                Log.v(TAG, "toast");
                mHandler.post(new ToastRunnable("", this));

            } else {
                PushWakeLock.acquireCpuWakeLock(this);

                Bundle bun = new Bundle();
                int start = extras.toString().indexOf("adviceId=");
                int size = extras.toString().length();
                String text = extras.toString().substring(start + 9);
                //int size=text.length();
                text = extras.toString().substring(start + 9, size - 2);
                Log.v(TAG, "text" + text);
                bun.putString("notiMessage", text);

                Intent popupIntent = new Intent(getApplicationContext(), KidsMindNotiActivity.class);
                popupIntent.putExtras(bun);

                PendingIntent pie = PendingIntent.getActivity(getApplicationContext(), 0, popupIntent,
                        PendingIntent.FLAG_ONE_SHOT);
                try {
                    pie.send();
                } catch (CanceledException e) {

                }
                Log.v(TAG, "?");
            }
            Log.i(TAG, "Received: " + extras.toString());
        }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReceiver.completeWakefulIntent(intent);
}

From source file:com.gsma.rcs.ri.sharing.video.VideoSharingIntentService.java

/**
 * Add video share notification//from w w w .j  a  v  a2  s.  co  m
 * 
 * @param invitation Intent invitation
 * @param vshDao the video sharing data object
 */
public void addVideoSharingInvitationNotification(Intent invitation, VideoSharingDAO vshDao) {
    if (vshDao.getContact() == null) {
        if (LogUtils.isActive) {
            Log.e(LOGTAG, "VideoSharingInvitationReceiver failed: cannot parse contact");
        }
        return;
    }
    /* Create pending intent */
    Intent intent = new Intent(invitation);
    intent.setClass(this, IncomingVideoSharing.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    /*
     * If the PendingIntent has the same operation, action, data, categories, components, and
     * flags it will be replaced. Invitation should be notified individually so we use a random
     * generator to provide a unique request code and reuse it for the notification.
     */
    int uniqueId = Utils.getUniqueIdForPendingIntent();
    PendingIntent contentIntent = PendingIntent.getActivity(this, uniqueId, intent,
            PendingIntent.FLAG_ONE_SHOT);

    String displayName = RcsContactUtil.getInstance(this).getDisplayName(vshDao.getContact());
    String notifTitle = getString(R.string.title_recv_video_sharing);

    /* Create notification */
    NotificationCompat.Builder notif = new NotificationCompat.Builder(this);
    notif.setContentIntent(contentIntent);
    notif.setSmallIcon(R.drawable.ri_notif_csh_icon);
    notif.setWhen(System.currentTimeMillis());
    notif.setAutoCancel(true);
    notif.setOnlyAlertOnce(true);
    notif.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    notif.setDefaults(Notification.DEFAULT_VIBRATE);
    notif.setContentTitle(notifTitle);
    notif.setContentText(getString(R.string.label_from_args, displayName));

    /* Send notification */
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    notificationManager.notify(uniqueId, notif.build());
}

From source file:com.instify.android.services.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *//*from  w w w  .  j  ava 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);

    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_notification_white).setContentTitle("FCM Message")
            .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.example.prahathessrengasamy.roomie.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *//*from  ww w .java  2s .  c  o  m*/
private void sendNotification(String messageTitle, String messageBody) {
    Intent intent = new Intent(this, SplashActivity.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.i1)
            //.setLargeIcon(R.mipmap.logos)
            .setLargeIcon(
                    BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.roomielogo))
            .setContentTitle(messageTitle).setContentText(messageBody).setAutoCancel(false).setOngoing(true)
            .setSound(defaultSoundUri).setContentIntent(pendingIntent);

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

    notificationManager.notify((int) System.currentTimeMillis() /* ID of notification */,
            notificationBuilder.build());
}

From source file:com.example.android.notifyme.MainActivity.java

/**
 * OnClick method for the "Notify Me!" button. Creates and delivers a simple notification
 */// w w w  .  j ava  2 s. com
public void sendNotification() {

    //Sets up the pending intent that is delivered when the notification is clicked
    Intent notificationIntent = new Intent(this, MainActivity.class);
    PendingIntent notificationPendingIntent = PendingIntent.getActivity(this, NOTIFICATION_ID,
            notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    // Sets up the pending intent to cancel the notification,
    // delivered when the user dismisses the notification
    Intent cancelIntent = new Intent(ACTION_CANCEL_NOTIFICATION);
    PendingIntent cancelPendingIntent = PendingIntent.getBroadcast(this, NOTIFICATION_ID, cancelIntent,
            PendingIntent.FLAG_ONE_SHOT);

    //Sets up the pending intent associated with the Learn More notification action,
    //uses an implicit intent to go to the web.
    Intent learnMoreIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(NOTIFICATION_GUIDE_URL));
    PendingIntent learnMorePendingIntent = PendingIntent.getActivity(this, NOTIFICATION_ID, learnMoreIntent,
            PendingIntent.FLAG_ONE_SHOT);

    //Sets up the pending intent to update the notification. Corresponds to a press of the
    //Update Me! button
    Intent updateIntent = new Intent(ACTION_UPDATE_NOTIFICATION);
    PendingIntent updatePendingIntent = PendingIntent.getBroadcast(this, NOTIFICATION_ID, updateIntent,
            PendingIntent.FLAG_ONE_SHOT);

    //Builds the notification with all of the parameters
    NotificationCompat.Builder notifyBuilder = new NotificationCompat.Builder(this)
            .setContentTitle(getString(R.string.notification_title))
            .setContentText(getString(R.string.notification_text)).setSmallIcon(R.drawable.ic_android)
            .setContentIntent(notificationPendingIntent).setPriority(NotificationCompat.PRIORITY_HIGH)
            .setDefaults(NotificationCompat.DEFAULT_ALL)
            .addAction(R.drawable.ic_learn_more, getString(R.string.learn_more), learnMorePendingIntent)
            .addAction(R.drawable.ic_update, getString(R.string.update), updatePendingIntent)
            .setDeleteIntent(cancelPendingIntent);

    //Delivers the notification
    mNotifyManager.notify(NOTIFICATION_ID, notifyBuilder.build());

    //Enables the update and cancel buttons but disables the "Notify Me!" button
    mNotifyButton.setEnabled(false);
    mUpdateButton.setEnabled(true);
    mCancelButton.setEnabled(true);

}

From source file:com.nuig.trafficapp.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.drawable.ic_warning_white_24dp).setContentTitle("RoadViser")
            .setContentText("New Incident: " + 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.example.sam.drawerlayoutprac.Partner.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param aNotificationMsgBody FCM message body received.
 *///w  w  w. j  a  v a 2  s . c om
private void sendNotification(String aNotificationMsgBody, Map<String, String> aDataMap) {
    Intent intent = new Intent(this, MainActivity.class);
    //?data-MainActivity.class -> ?bundle?("fcm")??:
    Set<String> keys = aDataMap.keySet();
    Bundle bundle = null;
    for (String key : keys) {
        bundle = new Bundle();
        bundle.putString(key, aDataMap.get(key));
    }
    intent.putExtras(bundle);

    // ?Notification:
    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);
    String fromMemId = aDataMap.get("fromMemId");
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.logo03_64dp).setColor(getResources().getColor(R.color.sub1_color))
            .setContentTitle("DDD hotel").setContentText(aNotificationMsgBody).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.android.sunshine.app.fcm.SunshineFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *///ww w.ja v a2s .co  m
private void sendNotification(String messageBody, int weatherId) {
    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);
    /*Bitmap largeIcon =
        BitmapFactory.decodeResource(this.getResources(), R.drawable.art_storm);*/
    Bitmap largeIcon = Utility.getBitmapIconFromWeatherID(this, weatherId);
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_b_w).setLargeIcon(largeIcon).setContentTitle("Sunshine Alert")
            .setContentText(messageBody).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent).setPriority(NotificationCompat.PRIORITY_HIGH);

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

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

From source file:com.owncloud.android.jobs.NotificationJob.java

private void sendNotification(String contentTitle, Account account) {
    Context context = getContext();
    Intent intent = new Intent(getContext(), NotificationsActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra(KEY_NOTIFICATION_ACCOUNT, account.name);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_ONE_SHOT);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.notification_icon)
            .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.notification_icon))
            .setColor(ThemeUtils.primaryColor(context)).setShowWhen(true).setSubText(account.name)
            .setContentTitle(contentTitle)
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)).setAutoCancel(true)
            .setContentIntent(pendingIntent);

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
        notificationBuilder.setChannelId(NotificationUtils.NOTIFICATION_CHANNEL_PUSH);
    }// www  . j  a va 2s  . co m

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

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