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:Main.java

public static void setAlarm(Context context, Intent intent, int notificationId, Calendar calendar) {
    intent.putExtra("NOTIFICATION_ID", notificationId);
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, notificationId, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
                pendingIntent);/*from   w w  w .j ava  2 s .  c  om*/
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        alarmManager.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
    } else {
        alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
    }
}

From source file:Main.java

public static void updateProgressNotification(Context context, int notifiId, String title, int progress) {
    Notification notification = new NotificationCompat.Builder(context).setAutoCancel(true).setTicker(title)
            .setContentTitle(title).setContentText("Downloading..." + progress + "%")
            .setProgress(100, progress, false)
            .setContentIntent(/*from  w  ww.  ja  v a  2s  .  com*/
                    PendingIntent.getActivity(context, 0, new Intent(), PendingIntent.FLAG_UPDATE_CURRENT))
            .setSmallIcon(android.R.drawable.stat_sys_download).build();
    updateNotification(context, notifiId, notification);
}

From source file:Main.java

public static PendingIntent scheduleLocalNotification(Context context, int slot, Long alertTime,
        String titleText, String subtitleText, String messageBodyText, String tickerText) {
    Log.i(TAG, "Scheduling local notification");
    Intent alertIntent = new Intent(getNotificationName(slot));
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, slot, alertIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    if (alarmManager != null) {
        alarmManager.set(AlarmManager.RTC_WAKEUP, alertTime, pendingIntent);
    }//  ww  w  .  j  ava 2  s  .c om
    return pendingIntent;
}

From source file:Main.java

public static PendingIntent scheduleLocalNotification(Context context, int slot, String title, String message,
        Long alertTime, int repeat) {
    Log.i(TAG, "Scheduling local notification");
    Intent alertIntent = new Intent(getNotificationName(slot));

    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, slot, alertIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    if (alarmManager != null) {
        if (repeat == 0) {
            alarmManager.set(AlarmManager.RTC_WAKEUP, alertTime, pendingIntent);
        } else {/*from  w  w w  .j  a  v a  2s  .c o  m*/
            Calendar alarmStartTime = Calendar.getInstance();
            alarmStartTime.add(Calendar.MINUTE, 1);
            alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, alertTime, repeat, pendingIntent);
        }
    }
    return pendingIntent;
}

From source file:Main.java

public static NotificationCompat.Builder buildNotification(Context context, Class<?> cls, int icon, int title,
        String text) {/*from   ww  w .j av a 2  s.c  o  m*/
    Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setSmallIcon(icon)
            .setContentTitle(context.getString(title)).setContentText(text).setAutoCancel(true).setSound(sound)
            .setTicker(text);
    Intent intent = new Intent(context, cls);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context).addParentStack(cls).addNextIntent(intent);
    PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(pendingIntent);
    return builder;
}

From source file:Main.java

public static void showNotification(long id, String titleString, String messageString, int iconResId,
        Context context, Class<?> className) {
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context).setSmallIcon(iconResId)
            .setContentTitle(titleString).setStyle(new NotificationCompat.BigTextStyle().bigText(messageString))
            .setContentText(messageString);
    Intent intent = new Intent(context, className);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(className);
    stackBuilder.addNextIntent(intent);/*from   ww w  .  ja va  2  s.  c  o m*/
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    NotificationManager mNotificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = mBuilder.build();
    notification.flags = Notification.FLAG_AUTO_CANCEL;
    mNotificationManager.notify((int) id, notification);
}

From source file:Main.java

public static <T extends BroadcastReceiver> void scheduleUpdate(Context context, Class<T> clazz) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(context, clazz);
    PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    Random random = new Random(System.currentTimeMillis());
    long offset = random.nextLong() % (12 * 60 * 60 * 1000);
    long interval = (24 * 60 * 60 * 1000) + offset;
    String prefKey = "pref_scheduled_monitor_config_update_" + clazz.getCanonicalName();
    long scheduledTime = preferences.getLong(prefKey, -1);

    if (scheduledTime == -1) {
        context.sendBroadcast(intent);//w ww. j  av  a2s .co  m
    }

    if (scheduledTime <= System.currentTimeMillis()) {
        context.sendBroadcast(intent);
        scheduledTime = System.currentTimeMillis() + interval;
        preferences.edit().putLong(prefKey, scheduledTime).commit();
        Log.w("PeriodicActionUtils",
                "Scheduling for all new time: " + scheduledTime + " (" + clazz.getSimpleName() + ")");
    } else {
        Log.w("PeriodicActionUtils", "Scheduling for time found in preferences: " + scheduledTime + " ("
                + clazz.getSimpleName() + ")");
    }

    am.cancel(sender);
    am.set(AlarmManager.RTC_WAKEUP, scheduledTime, sender);

    Log.w("PeriodicActionUtils", "Scheduled for: " + scheduledTime + " (" + clazz.getSimpleName() + ")");
}

From source file:com.boc.lfj.httpdemo.powerrv.demo.NotificationUtil.java

/**
 * ??MainActivity?/*from  w  w w  . j a va 2  s .  co m*/
 */
public static void sendSimplestNotificationWithAction(Context context) {

    NotificationManager mNotifyManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    //?PendingIntent
    Intent mainIntent = new Intent(context, NormalActivity.class);
    PendingIntent mainPendingIntent = PendingIntent.getActivity(context, 0, mainIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    // Notification.Builder 
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.mipmap.ic_launcher).setAutoCancel(true).setContentTitle("tittle")
            .setContentText("").setNumber(++NUMBER).setPriority(2)
            .setContentIntent(mainPendingIntent).setFullScreenIntent(mainPendingIntent, true);
    NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();

    String[] events = new String[] { "CCCCCCCCCCCCCCCCC", "DDDDDDDDDDDDDDDDDDDDD", "EEEEEEEEEEEEEEEEEEEE",
            "FFFFFFFFFFFFFFFFFFFF", "HHHHHHHHHHHHHHHHHHH" };
    // Sets a title for the Inbox in expanded layout
    inboxStyle.setBigContentTitle("Event tracker details:");
    // Moves events into the expanded layout
    for (String event : events) {
        inboxStyle.addLine(event);
    }

    NotificationCompat.BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle();
    bigPictureStyle.bigPicture(BitmapFactory.decodeResource(context.getResources(), R.mipmap.about_bg));
    bigPictureStyle.setSummaryText("DDDDDDDDDDDDDDDDDDDDD");
    // Moves the expanded layout object into the notification object.
    //        builder.setStyle(bigPictureStyle);

    //??
    Notification build = builder.build();

    mNotifyManager.notify(3, build);
}

From source file:bucci.dev.freestyle.NotificationCreator.java

public static void createTimerRunningNotification(Context context, String startPauseButtonState, long timeLeft,
        TimerType timerType, boolean extraButtonVisibleState) {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.bft_icon_gray)
            .setContentTitle(context.getString(R.string.notification_timer_running_text)).setAutoCancel(true)
            .setOngoing(true);//from   w  w w.  j  a  v  a 2s. c o  m

    Intent resultIntent = new Intent(context, TimerActivity.class);
    resultIntent.putExtra(StartActivity.TIMER_TYPE, timerType);
    resultIntent.putExtra(TimerActivity.START_PAUSE_STATE_PARAM, startPauseButtonState);
    resultIntent.putExtra(TimerActivity.TIME_LEFT_PARAM, timeLeft);
    if (extraButtonVisibleState)
        resultIntent.putExtra(TimerActivity.SHOW_EXTRA_ROUND_BUTTON_PARAM, true);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(TimerActivity.class);
    stackBuilder.addNextIntent(resultIntent);

    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(resultPendingIntent);

    NotificationManager mNotificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(NOTIFICATION_TIMER_RUNNING, builder.build());
}

From source file:com.adam.aslfms.service.ForegroundHide.java

@Override
public int onStartCommand(Intent i, int flags, int startId) {
    //Bundle extras = i.getExtras();

    Intent targetIntent = new Intent(mCtx, SettingsActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(mCtx, 0, targetIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(mCtx).setContentTitle("")
            .setSmallIcon(R.mipmap.ic_notify).setContentText("").setPriority(NotificationCompat.PRIORITY_MIN)
            .setContentIntent(contentIntent);

    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB_MR2) {
        builder.setLargeIcon(BitmapFactory.decodeResource(mCtx.getResources(), R.mipmap.ic_launcher));
    }//w w  w . j  ava  2  s.c  o  m

    this.startForeground(14619, builder.build());

    this.stopForeground(true);
    return Service.START_NOT_STICKY;
}