當前位置: 首頁>>代碼示例>>Java>>正文


Java AlarmManager.setAndAllowWhileIdle方法代碼示例

本文整理匯總了Java中android.app.AlarmManager.setAndAllowWhileIdle方法的典型用法代碼示例。如果您正苦於以下問題:Java AlarmManager.setAndAllowWhileIdle方法的具體用法?Java AlarmManager.setAndAllowWhileIdle怎麽用?Java AlarmManager.setAndAllowWhileIdle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.app.AlarmManager的用法示例。


在下文中一共展示了AlarmManager.setAndAllowWhileIdle方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onClick

import android.app.AlarmManager; //導入方法依賴的package包/類
public void onClick() {
    Log.i(TAG, "Click");

    // Cancel set alarm
    AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    PendingIntent pi = PendingIntent.getBroadcast(this, 0, new Intent(WidgetAdmin.INTENT_ON), PendingIntent.FLAG_UPDATE_CURRENT);
    am.cancel(pi);

    // Check state
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    boolean enabled = !prefs.getBoolean("enabled", false);
    prefs.edit().putBoolean("enabled", enabled).apply();
    if (enabled)
        ServiceSinkhole.start("tile", this);
    else {
        ServiceSinkhole.stop("tile", this);

        // Auto enable
        int auto = Integer.parseInt(prefs.getString("auto_enable", "0"));
        if (auto > 0) {
            Log.i(TAG, "Scheduling enabled after minutes=" + auto);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
                am.set(AlarmManager.RTC_WAKEUP, new Date().getTime() + auto * 60 * 1000L, pi);
            else
                am.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, new Date().getTime() + auto * 60 * 1000L, pi);
        }
    }
}
 
開發者ID:miankai,項目名稱:MKAPP,代碼行數:29,代碼來源:ServiceTileMain.java

示例2: start

import android.app.AlarmManager; //導入方法依賴的package包/類
public void start(Context c) {
    AlarmManager manager = (AlarmManager) c.getSystemService(Context.ALARM_SERVICE);
    int interval = 1000 * 60 * MainActivity.notificationTime;
    long currentTime = System.currentTimeMillis();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        manager.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, currentTime + interval, pendingIntent);
    } else {
        manager.set(AlarmManager.RTC_WAKEUP, currentTime + interval, pendingIntent);
    }
}
 
開發者ID:ccrama,項目名稱:Slide-RSS,代碼行數:11,代碼來源:NotificationJobScheduler.java

示例3: onReceive

import android.app.AlarmManager; //導入方法依賴的package包/類
@Override
public void onReceive(Context context, Intent intent) {
    super.onReceive(context, intent);

    Log.i(TAG, "Received " + intent);
    Util.logExtras(intent);

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

    // Cancel set alarm
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    PendingIntent pi = PendingIntent.getBroadcast(context, 0, new Intent(INTENT_ON), PendingIntent.FLAG_UPDATE_CURRENT);
    if (INTENT_ON.equals(intent.getAction()) || INTENT_OFF.equals(intent.getAction()))
        am.cancel(pi);

    // Vibrate
    Vibrator vs = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
    if (vs.hasVibrator())
        vs.vibrate(50);

    try {
        if (INTENT_ON.equals(intent.getAction()) || INTENT_OFF.equals(intent.getAction())) {
            boolean enabled = INTENT_ON.equals(intent.getAction());
            prefs.edit().putBoolean("enabled", enabled).apply();
            if (enabled)
                ServiceSinkhole.start("widget", context);
            else
                ServiceSinkhole.stop("widget", context);

            // Auto enable
            int auto = Integer.parseInt(prefs.getString("auto_enable", "0"));
            if (!enabled && auto > 0) {
                Log.i(TAG, "Scheduling enabled after minutes=" + auto);
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
                    am.set(AlarmManager.RTC_WAKEUP, new Date().getTime() + auto * 60 * 1000L, pi);
                else
                    am.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, new Date().getTime() + auto * 60 * 1000L, pi);
            }

        } else if (INTENT_LOCKDOWN_ON.equals(intent.getAction()) || INTENT_LOCKDOWN_OFF.equals(intent.getAction())) {
            boolean lockdown = INTENT_LOCKDOWN_ON.equals(intent.getAction());
            prefs.edit().putBoolean("lockdown", lockdown).apply();
            ServiceSinkhole.reload("widget", context);
            WidgetLockdown.updateWidgets(context);
        }
    } catch (Throwable ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }
}
 
開發者ID:miankai,項目名稱:MKAPP,代碼行數:50,代碼來源:WidgetAdmin.java

示例4: initAlarmManagerIfNotExists

import android.app.AlarmManager; //導入方法依賴的package包/類
/**
    * Diese Methode initialisiert den AlarmManager, sodass Notifications zu festgelegten
    * Uhrzeiten gesendet werden können, sofern dieser noch keinen Notification-PendingIntent verwaltet.
    */
   public static void initAlarmManagerIfNotExists() {

/*       if(getAlarmRunning())
           return; */ //TODO: FIXEN und wieder einfügen

       initServiceIntents();

       Calendar calendar = Calendar.getInstance();

       NotificationTime time;

       AlarmManager am = (AlarmManager) Utils.getContext().getSystemService(Context.ALARM_SERVICE);
       Utils.getController().registerAlarmManager(am);

       if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
           time = Utils.getNotificationTime(NotificationType.FOODMARKS);
           calendar.set(Calendar.HOUR_OF_DAY, time.hours);
           calendar.set(Calendar.MINUTE, time.minutes);

           am.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), Utils.getController().getFoodmarkReference());

           time = Utils.getNotificationTime(NotificationType.KLAUSUR);
           calendar.set(Calendar.HOUR_OF_DAY, time.hours);
           calendar.set(Calendar.MINUTE, time.minutes);
           am.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), Utils.getController().getKlausurplanReference());

           time = Utils.getNotificationTime(NotificationType.MOOD);
           calendar.set(Calendar.HOUR_OF_DAY, time.hours);
           calendar.set(Calendar.MINUTE, time.minutes);
           am.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), Utils.getController().getStimmungsbarometerReference());

           time = Utils.getNotificationTime(NotificationType.TIMETABLE);
           calendar.set(Calendar.HOUR_OF_DAY, time.hours);
           calendar.set(Calendar.MINUTE, time.minutes);
           am.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), Utils.getController().getTimetableReference());
       } else {
           time = Utils.getNotificationTime(NotificationType.FOODMARKS);
           calendar.set(Calendar.HOUR_OF_DAY, time.hours);
           calendar.set(Calendar.MINUTE, time.minutes);
           am.setRepeating(
                   AlarmManager.RTC_WAKEUP,
                   calendar.getTimeInMillis(),
                   AlarmManager.INTERVAL_DAY,
                   Utils.getController().getFoodmarkReference()
           );

           time = Utils.getNotificationTime(NotificationType.KLAUSUR);
           calendar.set(Calendar.HOUR_OF_DAY, time.hours);
           calendar.set(Calendar.MINUTE, time.minutes);
           am.setRepeating(
                   AlarmManager.RTC_WAKEUP,
                   calendar.getTimeInMillis(),
                   AlarmManager.INTERVAL_DAY,
                   Utils.getController().getKlausurplanReference()
           );

           time = Utils.getNotificationTime(NotificationType.MOOD);
           calendar.set(Calendar.HOUR_OF_DAY, time.hours);
           calendar.set(Calendar.MINUTE, time.minutes);
           am.setRepeating(
                   AlarmManager.RTC_WAKEUP,
                   calendar.getTimeInMillis(),
                   AlarmManager.INTERVAL_DAY,
                   Utils.getController().getStimmungsbarometerReference()
           );

           time = Utils.getNotificationTime(NotificationType.TIMETABLE);
           calendar.set(Calendar.HOUR_OF_DAY, time.hours);
           calendar.set(Calendar.MINUTE, time.minutes);
           am.setRepeating(
                   AlarmManager.RTC_WAKEUP,
                   calendar.getTimeInMillis(),
                   AlarmManager.INTERVAL_DAY,
                   Utils.getController().getTimetableReference()
           );
       }
   }
 
開發者ID:LCA311,項目名稱:leoapp-sources,代碼行數:82,代碼來源:NotificationAlarmHandler.java


注:本文中的android.app.AlarmManager.setAndAllowWhileIdle方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。