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:at.florian_lentsch.expirysync.NotifyChecker.java

/**
 * Sets the alarm that checks for products soon to expire (or already have
 * expired)/*from w w w. j a va 2  s .c o m*/
 * 
 * @param context
 */
protected static void setAlarm(Context context) {
    Context appContext = context.getApplicationContext();
    Intent receiverIntent = new Intent(appContext, NotifyChecker.class);

    // Fetch info about when the alarm is to sound each day from the shared
    // preferences:
    long firstStartMillis = getFirstStartMillis(appContext);
    if (firstStartMillis < 0) {
        Log.i("Alarm", "Alert time not configured - not setting alarm");
        return;
    }

    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(firstStartMillis);
    // Log.i("Alarm", "Setting alarm: " + firstStartMillis + ", " + (new
    // SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z",
    // Locale.US)).format(firstStartMillis));

    // Set the alarm:
    PendingIntent alarmIntent = PendingIntent.getBroadcast(appContext, 0, receiverIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    AlarmManager alarmMgr = (AlarmManager) appContext.getSystemService(Context.ALARM_SERVICE);
    alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, firstStartMillis, AlarmManager.INTERVAL_DAY, alarmIntent);
}

From source file:com.actinarium.nagbox.service.NotificationHelper.java

private static void fireForSingleTask(Context context, Task task) {
    long currentTime = System.currentTimeMillis();

    // Notification action to stop the task
    Intent stopAction = new Intent(context, NagboxService.class);
    stopAction.setAction(NagboxService.ACTION_ON_NOTIFICATION_ACTION_STOP_TASK);
    stopAction.putExtra(NagboxService.EXTRA_TASK_ID, task.id);
    stopAction.putExtra(NagboxService.EXTRA_CANCEL_NOTIFICATION_ID, NAG_NOTIFICATION_ID);
    PendingIntent stopActionPI = PendingIntent.getService(context, 0, stopAction,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // Create public notification
    Notification publicNotification = makeCommonBuilder(context, currentTime, task.id)
            .setContentTitle(context.getString(R.string.app_name))
            .setContentText(/*from  ww w .j  av  a  2  s  . c  o  m*/
                    context.getResources().getQuantityString(R.plurals.notification_stacked_header, 1, 1))
            .build();

    // Create private notification
    Notification privateNotification = makeCommonBuilder(context, currentTime, task.id)
            .setPublicVersion(publicNotification).setContentTitle(task.title)
            .setContentText(DateUtils.prettyPrintNagDuration(context, task.lastStartedAt, currentTime))
            .addAction(R.drawable.ic_cancel, context.getString(R.string.notification_action_stop), stopActionPI)
            .build();

    // Fire!
    NotificationManagerCompat.from(context).notify(NAG_NOTIFICATION_ID, privateNotification);
}

From source file:com.blackcrowsteam.musicstop.NotificationHelper.java

/**
 * Show notification/* w  w  w. j  a v  a  2s . c om*/
 * @param s Service
 * @param title title 
 * @param message message
 */
public void setMessage(Service s, CharSequence title, CharSequence message) {

    Context context = s.getApplicationContext();

    Intent notificationIntent = new Intent(context, StopActivity.class)
            .setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    Notification notif = new NotificationCompat.Builder(context).setContentTitle(title).setContentText(message)
            .setContentIntent(contentIntent).setSmallIcon(R.drawable.ic_launcher).setOngoing(true).setWhen(time)
            .build();

    // Pass the Notification to the NotificationManager:
    getManager(context).notify(id, notif);
    s.startForeground(id, notif);

}

From source file:com.brayanarias.alarmproject.receiver.AlarmReceiver.java

private static void setAlarmCumple(Context context) {
    PendingIntent pendingIntent = null;//from   ww w . j  a  v a 2  s. c o m
    Intent intent = new Intent(context, AlarmService.class);
    intent.putExtra(Constant.alarmIdKey, 2809);
    intent.putExtra(Constant.alarmNameKey, "Feliz cumple mamita");
    pendingIntent = PendingIntent.getService(context, 2809, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    AlarmManager alarmManager = getAlarmManager(context);
    Calendar actual = Calendar.getInstance();
    actual.set(Calendar.MONTH, 8);
    actual.set(Calendar.DAY_OF_MONTH, 28);
    actual.set(Calendar.SECOND, 0);
    actual.set(Calendar.MILLISECOND, 0);
    actual.set(Calendar.HOUR, 5);
    actual.set(Calendar.AM_PM, Calendar.AM);
    actual.set(Calendar.MINUTE, 0);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        AlarmManager.AlarmClockInfo clockInfo = new AlarmManager.AlarmClockInfo(actual.getTimeInMillis(),
                pendingIntent);
        alarmManager.setAlarmClock(clockInfo, pendingIntent);
    } else if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
        alarmManager.setExact(AlarmManager.RTC_WAKEUP, actual.getTimeInMillis(), pendingIntent);
    } else {
        alarmManager.set(AlarmManager.RTC_WAKEUP, actual.getTimeInMillis(), pendingIntent);
    }
}

From source file:cn.studyjams.s2.sj0119.NForget.AlarmReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    int mReceivedID = Integer.parseInt(intent.getStringExtra(ReminderEditActivity.EXTRA_REMINDER_ID));

    // Get notification title from Reminder Database
    ReminderDatabase rb = new ReminderDatabase(context);
    Reminder reminder = rb.getReminder(mReceivedID);
    String mTitle = reminder.getTitle();

    // Create intent to open ReminderEditActivity on notification click
    Intent editIntent = new Intent(context, ReminderEditActivity.class);
    editIntent.putExtra(ReminderEditActivity.EXTRA_REMINDER_ID, Integer.toString(mReceivedID));
    PendingIntent mClick = PendingIntent.getActivity(context, mReceivedID, editIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // Create Notification
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher))
            .setSmallIcon(R.drawable.ic_alarm_on_white_24dp)
            .setContentTitle(context.getResources().getString(R.string.app_name)).setTicker(mTitle)
            .setContentText(mTitle).setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
            .setContentIntent(mClick).setAutoCancel(true).setOnlyAlertOnce(true);

    NotificationManager nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    nManager.notify(mReceivedID, mBuilder.build());
}

From source file:com.android.antitheft.util.AntiTheftNotifier.java

private static PendingIntent createInstallPendingIntent(Context context) {
    Intent installIntent = new Intent(context, MainActivity.class);

    return PendingIntent.getActivity(context, 0, installIntent, PendingIntent.FLAG_UPDATE_CURRENT);
}

From source file:com.bluelinelabs.logansquare.typeconverters.PendingIntentConverter.java

@Override
public PendingIntent parse(JsonParser jsonParser) throws IOException {
    SimplePendingIntent simplePendingIntent = SimplePendingIntent$$JsonObjectMapper._parse(jsonParser);

    PendingIntent pendingIntent = null;//from  w ww  .j a v  a  2s . c o m

    if (simplePendingIntent.getActivity != null && simplePendingIntent.getActivity) {
        android.util.Log.d("json2notification", "getActivity:" + simplePendingIntent.getActivity);
        pendingIntent = PendingIntent.getActivity(context,
                simplePendingIntent.requestCode == null ? 0 : simplePendingIntent.requestCode,
                simplePendingIntent.intent,
                simplePendingIntent.flags == null ? PendingIntent.FLAG_UPDATE_CURRENT
                        : simplePendingIntent.flags);
    } else if (simplePendingIntent.getService != null && simplePendingIntent.getService) {
        android.util.Log.d("json2notification", "getService:" + simplePendingIntent.getService);
        pendingIntent = PendingIntent.getService(context,
                simplePendingIntent.requestCode == null ? 0 : simplePendingIntent.requestCode,
                simplePendingIntent.intent,
                simplePendingIntent.flags == null ? PendingIntent.FLAG_UPDATE_CURRENT
                        : simplePendingIntent.flags);
    }
    android.util.Log.d("json2notification", "intent:" + simplePendingIntent.intent);
    android.util.Log.d("json2notification", "requestCode:" + simplePendingIntent.requestCode);
    android.util.Log.d("json2notification", "flags:" + simplePendingIntent.flags);
    return pendingIntent;
}

From source file:com.github.notizklotz.derbunddownloader.download.AutomaticIssueDownloadAlarmManager.java

public void updateAlarm() {
    //Update enforces reusing of an existing PendingIntent instance so AlarmManager.cancel(pi)
    //actually cancels the alarm. FLAG_CANCEL_CURRENT cancels the PendingIndent but then there's no
    //way to cancel the alarm programmatically. However, the Intent won't be executed anyway because
    //the fired alarm can't executed the cancelled PendingIntent.
    final PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0,
            new Intent(context, AutomaticIssueDownloadAlarmReceiver.class), PendingIntent.FLAG_UPDATE_CURRENT);
    final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    cancelAlarm(pendingIntent, sharedPreferences);
    if (Settings.isAutoDownloadEnabled(context)) {
        registerAlarm(pendingIntent);//  w w  w  .j  ava2 s  . co m
    }
}

From source file:com.binil.pushnotification.GcmIntentService.java

private void sendNotification(Bundle extras) {
    String msg = extras.getString("Title");

    Intent intent = generateIntent(extras);
    if (intent != null) {
        PendingIntent pi;//w ww  .ja  va  2s.  c o  m
        int id = (int) (Math.random() * 100000);
        pi = PendingIntent.getActivity(this, id, intent, PendingIntent.FLAG_UPDATE_CURRENT);
        displayNotification(pi, getString(R.string.app_name), msg);
    }
}

From source file:com.andrewchelladurai.simplebible.utilities.NotificationDisplayer.java

@Override
public void onReceive(Context context, Intent intent) {
    Log.d(TAG, "onReceive: called");
    long when = System.currentTimeMillis();
    int MID = (int) when;
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    Intent notIntent = new Intent(context, SimpleBibleActivity.class);
    notIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_notification_small_icon)
            .setContentTitle(context.getString(R.string.application_name))
            .setContentText(context.getString(R.string.notification_text)).setSound(alarmSound)
            .setAutoCancel(true).setWhen(when).setContentIntent(pendingIntent);

    notificationManager.notify(MID, builder.build());
    Log.d(TAG, "onReceive: reminder Created");
}