当前位置: 首页>>代码示例>>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;未经允许,请勿转载。