Example usage for android.app PendingIntent FLAG_UPDATE_CURRENT

List of usage examples for android.app PendingIntent FLAG_UPDATE_CURRENT

Introduction

In this page you can find the example usage for android.app PendingIntent FLAG_UPDATE_CURRENT.

Prototype

int FLAG_UPDATE_CURRENT

To view the source code for android.app PendingIntent FLAG_UPDATE_CURRENT.

Click Source Link

Document

Flag indicating that if the described PendingIntent already exists, then keep it but replace its extra data with what is in this new Intent.

Usage

From source file:com.alchemiasoft.book.service.BookActionService.java

@Override
protected void onHandleIntent(Intent intent) {
    final int notificationId = intent.getIntExtra(EXTRA_NOTIFICATION_ID, NOT_VALID_NOTIFICATION);
    // Cancelling any shown notification
    if (notificationId != NOT_VALID_NOTIFICATION) {
        Log.d(TAG_LOG, "Dismissing notification with id=" + notificationId);
        NotificationManagerCompat.from(this).cancel(notificationId);
    }/* w  w  w.jav a2  s .c o  m*/
    final long bookId = intent.getLongExtra(EXTRA_BOOK_ID, NOT_VALID_BOOK);
    if (bookId != NOT_VALID_BOOK) {
        final ContentResolver cr = getContentResolver();
        final Action action = Action.valueOf(intent.getAction());
        Log.d(TAG_LOG, "Performing action=" + action + " on book with id=" + bookId);
        final ContentValues cv = new ContentValues();
        switch (action) {
        case BUY:
            cv.put(BookDB.Book.OWNED, 1);
            if (cr.update(BookDB.Book.create(bookId), cv, null, null) == 1
                    && intent.getBooleanExtra(EXTRA_WEARABLE_INPUT, false)) {
                final Book book = getBook(bookId);
                if (book != null) {
                    final NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
                    builder.setSmallIcon(R.drawable.ic_launcher).setAutoCancel(true)
                            .setContentTitle(getString(R.string.book_purchased))
                            .setContentText(book.getTitle());
                    builder.setContentIntent(PendingIntent.getActivity(this, 0,
                            HomeActivity.createFor(this, book), PendingIntent.FLAG_UPDATE_CURRENT));

                    // ONLY 4 WEARABLE(s)
                    final NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender();
                    wearableExtender
                            .setBackground(BitmapFactory.decodeResource(getResources(), R.drawable.background));
                    // ACTION TO SELL A BOOK FROM A WEARABLE
                    final PendingIntent sellIntent = PendingIntent.getService(
                            this, 0, BookActionService.IntentBuilder.sell(this, book)
                                    .notificationId(NOTIFICATION_ID).wearableInput().build(),
                            PendingIntent.FLAG_UPDATE_CURRENT);
                    wearableExtender.addAction(new NotificationCompat.Action.Builder(R.drawable.ic_action_sell,
                            getString(R.string.action_sell), sellIntent).build());
                    // Finally extending the notification
                    builder.extend(wearableExtender);

                    NotificationManagerCompat.from(this).notify(NOTIFICATION_ID, builder.build());
                }
            }
            break;
        case SELL:
            cv.put(BookDB.Book.OWNED, 0);
            if (cr.update(BookDB.Book.create(bookId), cv, null, null) == 1
                    && intent.getBooleanExtra(EXTRA_WEARABLE_INPUT, false)) {
                final Book book = getBook(bookId);
                if (book != null) {
                    final NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
                    builder.setSmallIcon(R.drawable.ic_launcher).setAutoCancel(true)
                            .setContentTitle(getString(R.string.book_sold)).setContentText(book.getTitle());
                    builder.setContentIntent(PendingIntent.getActivity(this, 0,
                            HomeActivity.createFor(this, book), PendingIntent.FLAG_UPDATE_CURRENT));

                    NotificationManagerCompat.from(this).notify(NOTIFICATION_ID, builder.build());
                }
            }
            break;
        case ADD_NOTE:
            final CharSequence notes = getExtraNotes(intent);
            if (!TextUtils.isEmpty(notes)) {
                cv.put(BookDB.Book.NOTES, notes.toString());
                cr.update(BookDB.Book.create(bookId), cv, null, null);
            }
            break;
        default:
            break;
        }
    }
}

From source file:com.androidinspain.deskclock.alarms.AlarmNotifications.java

static synchronized void showHighPriorityNotification(Context context, AlarmInstance instance) {
    LogUtils.v("Displaying high priority notification for alarm instance: " + instance.mId);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setShowWhen(false)
            .setContentTitle(/* w  w w.  ja  va2s .co  m*/
                    context.getString(com.androidinspain.deskclock.R.string.alarm_alert_predismiss_title))
            .setContentText(AlarmUtils.getAlarmText(context, instance, true /* includeLabel */))
            .setColor(ContextCompat.getColor(context, com.androidinspain.deskclock.R.color.default_background))
            .setSmallIcon(com.androidinspain.deskclock.R.drawable.stat_notify_alarm).setAutoCancel(false)
            .setSortKey(createSortKey(instance)).setPriority(NotificationCompat.PRIORITY_HIGH)
            .setCategory(NotificationCompat.CATEGORY_ALARM).setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setLocalOnly(true);

    if (Utils.isNOrLater()) {
        builder.setGroup(UPCOMING_GROUP_KEY);
    }

    // Setup up dismiss action
    Intent dismissIntent = AlarmStateManager.createStateChangeIntent(context,
            AlarmStateManager.ALARM_DISMISS_TAG, instance, AlarmInstance.PREDISMISSED_STATE);
    final int id = instance.hashCode();
    builder.addAction(com.androidinspain.deskclock.R.drawable.ic_alarm_off_24dp,
            context.getString(com.androidinspain.deskclock.R.string.alarm_alert_dismiss_text),
            PendingIntent.getService(context, id, dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT));

    // Setup content action if instance is owned by alarm
    Intent viewAlarmIntent = createViewAlarmIntent(context, instance);
    builder.setContentIntent(
            PendingIntent.getActivity(context, id, viewAlarmIntent, PendingIntent.FLAG_UPDATE_CURRENT));

    NotificationManagerCompat nm = NotificationManagerCompat.from(context);
    final Notification notification = builder.build();
    nm.notify(id, notification);
    updateUpcomingAlarmGroupNotification(context, -1, notification);
}

From source file:luan.com.flippit.GcmIntentService.java

private void textNotification(String msg) {
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MyActivity.class),
            PendingIntent.FLAG_UPDATE_CURRENT);

    Log.i(MyActivity.TAG, getClass().getName() + ": " + "Text message.");

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.action_icon).setContentTitle("FlippIt")
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setTicker("Copied to clipboard")
            .setContentText(msg);/* w  w w . j av a 2s .com*/

    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.cancel(1);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
    new CopyClipboard(msg, mContext);
    UpdateHistory updateHistory = new UpdateHistory();
    updateHistory.updateHistory(mContext);
}

From source file:com.anthonykeane.speedzone.ActivityRecognitionIntentService.java

/**
 * Get a content Intent for the notification
 *
 * @return A PendingIntent that starts the device's Location Settings panel.
 *//*www .j  a  v a 2 s .  c  o  m*/
private PendingIntent WhatToDoWhenNotificationIsClicked() {

    // Set the Intent action to open Location Settings
    Intent gpsIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);

    // Create a PendingIntent to start an Activity
    return PendingIntent.getActivity(getApplicationContext(), 0, gpsIntent, PendingIntent.FLAG_UPDATE_CURRENT);
}

From source file:com.apexlabs.alarm.AlarmService.java

private void postNotification() {
    Log.d(TAG, "posting notification");
    mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.transparent)
            //.setLargeIcon(BitmapFactory.decodeResource(getApplicationContext().getResources(),R.drawable.alarm_white))
            .setContentTitle(getResources().getString(R.string.notification_title))
            .setContentText("Next Alarm is " + Settings.System
                    .getString(getContentResolver(), Settings.System.NEXT_ALARM_FORMATTED).toString());

    notificationPosted = true;// ww w.  j  av  a 2  s  .c om
    Intent nIntent = getClockIntent();
    nIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(AlarmNotification.class);
    stackBuilder.addNextIntent(nIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);

    // should make mId random
    mId = 867;
    mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    mNotificationManager.notify(mId, mBuilder.build());
}

From source file:com.chintans.venturebox.util.Utils.java

public static void setAlarm(Context context, long time, boolean trigger, boolean isRom) {

    Intent i = new Intent(context, NotificationAlarm.class);
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    PendingIntent pi = PendingIntent.getBroadcast(context, isRom ? ROM_ALARM_ID : GAPPS_ALARM_ID, i,
            PendingIntent.FLAG_UPDATE_CURRENT);

    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    am.cancel(pi);//from ww w.  j a  v a2s.  c om
    if (time > 0) {
        am.setInexactRepeating(AlarmManager.RTC_WAKEUP, trigger ? 0 : time, time, pi);
    }
}

From source file:com.balch.mocktrade.services.OrderService.java

private void sendNotification(Order order, String msg) {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle(this.getString(R.string.notification_order_title))
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg);

    // TODO: Make this go somewhere cool
    Intent clickIntent = new Intent(this, TemplateActivity.class);

    PendingIntent pendingClickIntent = PendingIntent.getActivity(this, 0, clickIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(pendingClickIntent);
    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    //        int id = R.id.notification_order_id;
    int id = (int) (order.getId() % Integer.MAX_VALUE);
    notificationManager.notify(id, builder.build());
}

From source file:com.bhb27.isu.tools.Tools.java

public static void DoNotification(Context context) {

    NotificationCompat.Builder notification = new NotificationCompat.Builder(context);
    notification.setSmallIcon(R.drawable.ic_notification);
    notification.setContentTitle(context.getString(R.string.notification_title));
    notification.setOngoing(true);//from   w  w  w .  ja  va2 s  .c o m
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(context.NOTIFICATION_SERVICE);

    Intent yesReceiver = new Intent();
    yesReceiver.setAction(Constants.YES_ACTION);
    PendingIntent pendingIntentYes = PendingIntent.getBroadcast(context, 12345, yesReceiver,
            PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Action actiony = new NotificationCompat.Action.Builder(R.drawable.ic_notification,
            context.getString(R.string.yes), pendingIntentYes).build();
    notification.addAction(actiony);

    Intent dismissReceiver = new Intent();
    dismissReceiver.setAction(Constants.DISSMISS_ACTION);
    PendingIntent pendingIntentYes2 = PendingIntent.getBroadcast(context, 12345, dismissReceiver,
            PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Action actionn = new NotificationCompat.Action.Builder(R.drawable.ic_notification,
            context.getString(R.string.dismiss), pendingIntentYes2).build();
    notification.addAction(actionn);

    notificationManager.notify(10, notification.build());
}

From source file:com.example.gemswin.screencastrecevertest.MainActivity_Reciever.java

 @Override
protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_main_reciever);
   WifiManager wm = (WifiManager) getSystemService(WIFI_SERVICE);
   String ip = Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress());
   TextView text = (TextView) findViewById(R.id.textView);


   planetList = new ArrayList<String>();

   mTextureView = (TextureView)findViewById(R.id.textureView);
   mTextureView.setSurfaceTextureListener(this);
   mTextureView.requestLayout();//from ww w  . j  a v a2s.c o m
   mTextureView.invalidate();
   mTextureView.setOpaque(false);
   logout = (Button) findViewById(R.id.logout);
   cast = (Button) findViewById(R.id.castAsmaster);


   doubtbutton = (Button) findViewById(R.id.doubt);
   viewbutton = (Button) findViewById(R.id.viewdoubt);

   pref = new PrefManager(getApplicationContext());
   text.setText(ip);
   logout.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
         pref.logout();
         Intent i = new Intent(MainActivity_Reciever.this, LoginActivity.class);
         startActivity(i);
         finish();
      }
   });
   cast.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {

         new allowcast().execute();
      }
   });
   viewbutton.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
         //pref.logout();                                               // LOOK HERE ASH
         /*Intent i = new Intent(MainActivity_Reciever.this,DoubtActivity.class);
         startActivity(i);*/
         new viewdoubttask().execute();


      }
   });

   doubtbutton.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
         //pref.logout();                                               // LOOK HERE ASH
         /*Intent i = new Intent(MainActivity_Reciever.this,DoubtActivity.class);
         startActivity(i);*/
         DoubtBox();

      }
   });

   mTask = new ReceiverAsyncTask(this);
   mTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);

   Intent intent1 = new Intent(this, MyBroadcastReceiver.class);
   intent1.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
   PendingIntent pendingIntent = PendingIntent.getBroadcast(
         getApplicationContext(), 234324243, intent1, PendingIntent.FLAG_UPDATE_CURRENT);
   AlarmManager alarmManager = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
   alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (10 * 1000), pendingIntent);


}

From source file:com.android.email.EmailNotificationController.java

/**
 * Returns a {@link android.support.v4.app.NotificationCompat.Builder} for an event with the
 * given account. The account contains specific rules on ring tone usage and these will be used
 * to modify the notification behaviour.
 *
 * @param accountId The id of the account this notification is being built for.
 * @param ticker Text displayed when the notification is first shown. May be {@code null}.
 * @param title The first line of text. May NOT be {@code null}.
 * @param contentText The second line of text. May NOT be {@code null}.
 * @param intent The intent to start if the user clicks on the notification.
 * @param number A number to display using {@link Builder#setNumber(int)}. May be {@code null}.
 * @param enableAudio If {@code false}, do not play any sound. Otherwise, play sound according
 *        to the settings for the given account.
 * @return A {@link Notification} that can be sent to the notification service.
 *//* w  w w  . jav a 2  s. c om*/
private NotificationCompat.Builder createBaseAccountNotificationBuilder(long accountId, String ticker,
        CharSequence title, String contentText, Intent intent, Integer number, boolean enableAudio,
        boolean ongoing) {
    // Pending Intent
    PendingIntent pending = null;
    if (intent != null) {
        pending = PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    }

    // NOTE: the ticker is not shown for notifications in the Holo UX
    final NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext).setContentTitle(title)
            .setContentText(contentText).setContentIntent(pending).setNumber(number == null ? 0 : number)
            .setSmallIcon(R.drawable.ic_notification_mail_24dp).setWhen(mClock.getTime()).setTicker(ticker)
            .setOngoing(ongoing);

    if (enableAudio) {
        Account account = Account.restoreAccountWithId(mContext, accountId);
        setupSoundAndVibration(builder, account);
    }

    return builder;
}