Code example for Context

Methods: getBroadcastgetSystemService

0
    public static final String PREF_REENGAGEMENT_COUNT = "pref_reengagement_count"; //$NON-NLS-1$
 
    public static final String BROADCAST_SHOW_REENGAGEMENT = Constants.PACKAGE + ".SHOW_REENGAGEMENT"; //$NON-NLS-1$
 
    public static void scheduleReengagementAlarm(Context context) {
        AlarmManager am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
        Intent intent = new Intent(BROADCAST_SHOW_REENGAGEMENT);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(context, REQUEST_CODE, intent, 0);
        am.cancel(pendingIntent);
 
        long time = getNextReminderTime();
        am.set(AlarmManager.RTC_WAKEUP, time, pendingIntent);
    } 
 
    private static long getNextReminderTime() { 
        int reengagementReminders = Preferences.getInt(PREF_REENGAGEMENT_COUNT, 1);
        int days;
        if (DateUtilities.now() - Preferences.getLong(AstridPreferences.P_FIRST_LAUNCH, 0) > DateUtilities.ONE_DAY * 30) { // Installed longer than 30 days
            // Sequence: every 6, 8, 10 days 
            days = Math.min(10, 4 + 2 * reengagementReminders);
        } else {