Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.util.Calendar;
import android.app.AlarmManager;
import android.app.PendingIntent;

import android.os.Build;

public class Main {
    public static final int FAKE_KITKAT_WATCH = 19;

    public static void setupNotificationMessage(AlarmManager am, Calendar calendar, int interval,
            PendingIntent sender) {
        // official docs:
        // Note: as of API 19, all repeating alarms are inexact. If your application needs precise 
        // delivery times then it must use one-time exact alarms, rescheduling each time as described above. 
        // Legacy applications whosetargetSdkVersion is earlier than API 19 will continue to have all of their alarms, including repeating alarms, treated as exact.
        if (Build.VERSION.SDK_INT >= FAKE_KITKAT_WATCH) {
            //am.setWindow(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 20000, sender);
            am.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), sender);
        } else {
            // use this on sdk level 18 and smaller than 18. later sdk won`t guarantee time to be precise.
            //am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), interval, sender);
            am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), sender);
        }
    }
}