setup Notification Message - Android Android OS

Android examples for Android OS:Notification

Description

setup Notification Message

Demo Code


//package com.java2s;
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 {//from   w w w.  j av a 2s  .  c o m
            // 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);
        }
    }
}

Related Tutorials