当前位置: 首页>>代码示例>>Java>>正文


Java AlarmManager.setInexactRepeating方法代码示例

本文整理汇总了Java中android.app.AlarmManager.setInexactRepeating方法的典型用法代码示例。如果您正苦于以下问题:Java AlarmManager.setInexactRepeating方法的具体用法?Java AlarmManager.setInexactRepeating怎么用?Java AlarmManager.setInexactRepeating使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.app.AlarmManager的用法示例。


在下文中一共展示了AlarmManager.setInexactRepeating方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setTimeInterval

import android.app.AlarmManager; //导入方法依赖的package包/类
public static void setTimeInterval(Context context){
    Log.d(TAG, "Entered set time interval");
    Intent selfIntent = getIntent(context);
    PendingIntent pendingIntent = PendingIntent.getService(context, 0,
            selfIntent, 0);

    AlarmManager manager = (AlarmManager) context.getSystemService
            (Context.ALARM_SERVICE);

    if (isTimeAlarmOn(context)){
        manager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
                SystemClock.elapsedRealtime(), REPEAT_TIME,
                pendingIntent);
        Log.d(TAG, "Alarm is not on, starting it now");
    }else {
        manager.cancel(pendingIntent);
        pendingIntent.cancel();
        Log.d(TAG, "Alarm is on, cancelling it now");
    }
}
 
开发者ID:aumarbello,项目名称:WalkGraph,代码行数:21,代码来源:TimeService.java

示例2: scheduleNotifAlarm

import android.app.AlarmManager; //导入方法依赖的package包/类
public void scheduleNotifAlarm() {
    AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    Intent intent = new Intent(this, NotifAlarmReceiver.class);
    PendingIntent alarmIntent = PendingIntent.getBroadcast(this, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.set(Calendar.HOUR_OF_DAY, 14);
    calendar.set(Calendar.MINUTE,39);
    alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, alarmIntent);
    Log.d("mainactivity","true");

    Calendar calendar1 = Calendar.getInstance();
    calendar1.setTimeInMillis(System.currentTimeMillis());
    calendar1.set(Calendar.HOUR_OF_DAY, 12);
    alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, alarmIntent);
}
 
开发者ID:Ronak-59,项目名称:Trinity-App,代码行数:18,代码来源:MainActivity.java

示例3: schedule

import android.app.AlarmManager; //导入方法依赖的package包/类
/**
 * Schedule or cancel this service to update the app index, according to the
 * current preferences. Should be called a) at boot, b) if the preference
 * is changed, or c) on startup, in case we get upgraded.
 */
public static void schedule(Context ctx) {

    SharedPreferences prefs = PreferenceManager
            .getDefaultSharedPreferences(ctx);
    String sint = prefs.getString(Preferences.PREF_UPD_INTERVAL, "0");
    int interval = Integer.parseInt(sint);

    Intent intent = new Intent(ctx, UpdateService.class);
    PendingIntent pending = PendingIntent.getService(ctx, 0, intent, 0);

    AlarmManager alarm = (AlarmManager) ctx
            .getSystemService(Context.ALARM_SERVICE);
    alarm.cancel(pending);
    if (interval > 0) {
        alarm.setInexactRepeating(AlarmManager.ELAPSED_REALTIME,
                SystemClock.elapsedRealtime() + 5000,
                AlarmManager.INTERVAL_HOUR, pending);
        Utils.debugLog(TAG, "Update scheduler alarm set");
    } else {
        Utils.debugLog(TAG, "Update scheduler alarm not set");
    }

}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:29,代码来源:UpdateService.java

示例4: startPostDataService

import android.app.AlarmManager; //导入方法依赖的package包/类
/**
 * Start post data service.
 */
public void startPostDataService() {
    try {
        int dataInterval = SharedPreferenceHelper.getSharedPreferenceInt(getApplicationContext(), Constants.KEY_SYNC_INTERVAL, AppUtility.DEFAULT_SYNC_INTERVAL);
        //Create a new PendingIntent and add it to the AlarmManager
        Intent intent = new Intent(getApplicationContext(), PostDataService.class);
        pendingIntent =
                PendingIntent.getBroadcast(getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
        AlarmManager alarmManager =
                (AlarmManager) getSystemService(Activity.ALARM_SERVICE);
        int intervalInMinutes = dataInterval * AppUtility.TIME_ONE_MINUTE;
        alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, intervalInMinutes,
                intervalInMinutes, pendingIntent);

    } catch (Exception e) {
        Log.e(AppUtility.TAG, Log.getStackTraceString(e));
    }
}
 
开发者ID:Welloculus,项目名称:MobileAppForPatient,代码行数:21,代码来源:HealthCareApp.java

示例5: setAlarm

import android.app.AlarmManager; //导入方法依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.N)
public static void setAlarm(Context context,int hour, int minute, int second) {
    Calendar calendar = Calendar.getInstance();
    Calendar rightNow = Calendar.getInstance();
    calendar.set(Calendar.HOUR, hour);
    int timeOffset = hour - calendar.get(Calendar.HOUR);
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.set(Calendar.HOUR, hour - timeOffset);
    calendar.set(Calendar.MINUTE, minute);
    calendar.set(Calendar.SECOND, second);

    Intent intent = new Intent(context, AlarmReceiver.class);
    pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
    alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    //set the alarm repeat one day
    alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP,
            calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
    Log.i("setting", String.valueOf(calendar.getTime()));
    Log.i("actual", String.valueOf(rightNow.getTime()));
}
 
开发者ID:MessageOnTap,项目名称:ImHome,代码行数:22,代码来源:AlarmUtils.java

示例6: setRecurringAlarm

import android.app.AlarmManager; //导入方法依赖的package包/类
public static void setRecurringAlarm(Context context) {
    String intervalPref = PreferenceManager.getDefaultSharedPreferences(context)
            .getString("refreshInterval", "1");
    Intent refresh = new Intent(context, AlarmReceiver.class);
    PendingIntent recurringRefresh = PendingIntent.getBroadcast(context,
            0, refresh, PendingIntent.FLAG_CANCEL_CURRENT);
    AlarmManager alarms = (AlarmManager) context.getSystemService(
            Context.ALARM_SERVICE);
    long intervalMillis = intervalMillisForRecurringAlarm(intervalPref);
    if (intervalMillis == 0) {
        // Cancel previous alarm
        alarms.cancel(recurringRefresh);
    } else {
        alarms.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
                SystemClock.elapsedRealtime() + intervalMillis,
                intervalMillis,
                recurringRefresh);
    }
}
 
开发者ID:hichemcesar24,项目名称:Weather-Android,代码行数:20,代码来源:AlarmReceiver.java

示例7: setNotificationAlarmMainPrayer

import android.app.AlarmManager; //导入方法依赖的package包/类
/**
 * Function to set daily prayer calculate broadcast
 *
 * @param context Context
 */
public static void setNotificationAlarmMainPrayer(Context context) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.set(Calendar.HOUR_OF_DAY, 1);
    calendar.set(Calendar.MINUTE, 0);

    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent alarmReceiver = new Intent(context, PrayingDayCalculateAlarm.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 1111, alarmReceiver, PendingIntent.FLAG_UPDATE_CURRENT);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        // kitkat...
        alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP,
                calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
    } else {
        alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
                calendar.getTimeInMillis(), 1000 * 60 * 60 * 24, pendingIntent);
    }
}
 
开发者ID:fekracomputers,项目名称:MuslimMateAndroid,代码行数:24,代码来源:Alarms.java

示例8: setAlarm

import android.app.AlarmManager; //导入方法依赖的package包/类
/**
 * Sets a daily recurring alarm that is to trigger that
 * 2 am device time.
 */
public static void setAlarm(Context context) {
    DebugLog.logMethod();
    context.getApplicationContext();

    PendingIntent pendingIntent = getPendingIntent(context);
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, 2);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);

    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    alarmManager.setInexactRepeating(
            AlarmManager.RTC_WAKEUP,
            calendar.getTimeInMillis(),
            AlarmManager.INTERVAL_DAY,
            pendingIntent
    );
}
 
开发者ID:darsh2,项目名称:CouponsTracker,代码行数:23,代码来源:AppWidgetAlarmManager.java

示例9: setAlarm

import android.app.AlarmManager; //导入方法依赖的package包/类
/**
 * Sets a daily recurring alarm with time according to user preference.
 * If app notifications are disabled, this method does nothing.
 */
public static void setAlarm(Context context) {
    DebugLog.logMethod();
    context = context.getApplicationContext();

    SharedPreferences sharedPreferences = PreferenceManager
            .getDefaultSharedPreferences(context);
    if (!sharedPreferences.getBoolean(SettingsFragment.KEY_NOTIFICATION_STATE, true)) {
        return;
    }

    int notificationTime = sharedPreferences.getInt(
            SettingsFragment.KEY_NOTIFICATION_TIME,
            SettingsFragment.DEFAULT_NOTIFICATION_TIME
    );
    PendingIntent pendingIntent = getPendingIntent(context);
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, notificationTime / 100);
    calendar.set(Calendar.MINUTE, notificationTime % 100);
    calendar.set(Calendar.SECOND, 0);

    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    alarmManager.setInexactRepeating(
            AlarmManager.RTC_WAKEUP,
            calendar.getTimeInMillis(),
            AlarmManager.INTERVAL_DAY,
            pendingIntent
    );
}
 
开发者ID:darsh2,项目名称:CouponsTracker,代码行数:33,代码来源:NotificationAlarmManager.java

示例10: onCreate

import android.app.AlarmManager; //导入方法依赖的package包/类
@Override
public void onCreate() {
	EDDBHelper dbHelper = new EDDBHelper(this);
	if (EDApplication.volumeList==null) EDApplication.volumeList = dbHelper.getVolumes();
	
	AlarmManager alarmMgr = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
	PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, new Intent(this, FileSynchronizerAlarmReceiver.class),PendingIntent.FLAG_CANCEL_CURRENT);
	// Use inexact repeating which is easier on battery (system can phase events and not wake at exact times)
	alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,  AlarmManager.INTERVAL_HOUR, AlarmManager.INTERVAL_HOUR, pendingIntent);
	instance = this;
	mApp = (EDApplication) getApplication();
	List<FileSynchronizerRule> syncRules = mApp.getDbHelper().getSyncRules();
	FileSynchronizerService.refreshRules(syncRules);
}
 
开发者ID:starn,项目名称:encdroidMC,代码行数:15,代码来源:FileSynchronizerService.java

示例11: setAlarm

import android.app.AlarmManager; //导入方法依赖的package包/类
private void setAlarm() {
    Log.d(TAG, "setAlarm");

    Intent intent = new Intent(this, AlarmNotification.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 234324243, intent, 0);
    AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    long firstRun = System.currentTimeMillis() + THREE_MINUTES;
    alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, firstRun, THREE_MINUTES, pendingIntent);
}
 
开发者ID:PacktPublishing,项目名称:Android-Wear-Projects,代码行数:10,代码来源:WearStepService.java

示例12: SetupAlarm

import android.app.AlarmManager; //导入方法依赖的package包/类
private void SetupAlarm() {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.add(Calendar.SECOND, 30);
    Intent myIntent = new Intent(getBaseContext(), RestartServiceReceiver.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(getBaseContext(), 1, myIntent,0);
    AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
    alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
    long frequency = 10800 * 1000; // in ms
    alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), frequency, pendingIntent);
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:12,代码来源:LaunchActivity.java

示例13: setAlarm

import android.app.AlarmManager; //导入方法依赖的package包/类
public static void setAlarm(Activity activity) {
    AlarmManager alarmManager = (AlarmManager) activity.getSystemService(Context.ALARM_SERVICE);
    alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
            SystemClock.elapsedRealtime(),
            AlarmManager.INTERVAL_FIFTEEN_MINUTES, getAlarmPendingIntent(activity));
    PreferencesUtils.getPreferences(activity).edit()
            .putLong(BreventReceiver.ALARM_TIME, SystemClock.elapsedRealtime()).apply();
    UILog.i("setAlarm");
}
 
开发者ID:brevent,项目名称:Brevent,代码行数:10,代码来源:BreventActivity.java

示例14: startAlarm

import android.app.AlarmManager; //导入方法依赖的package包/类
public void startAlarm() {
    Calendar calendar = Calendar.getInstance();
    Intent intent = new Intent(getApplicationContext(), Notification_receiver.class);
    alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 100, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    calendar.set(Calendar.HOUR_OF_DAY, h);
    calendar.set(Calendar.MINUTE, m);
    alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 1000 * 60 * 60 * 24, pendingIntent);
    Toast.makeText(Notificacoes.this, "Alarme definido para " + h + ":" + m + "min", Toast.LENGTH_SHORT).show();
}
 
开发者ID:jvbeltra,项目名称:JavaIsFun,代码行数:11,代码来源:Notificacoes.java

示例15: scheduleRecommendationUpdate

import android.app.AlarmManager; //导入方法依赖的package包/类
private void scheduleRecommendationUpdate(Context context) {
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent recommendationIntent = new Intent(context, UpdateRecommendationsService.class);
    PendingIntent alarmIntent = PendingIntent.getService(context, 0, recommendationIntent, 0);

    alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, INITIAL_DELAY,
            AlarmManager.INTERVAL_HALF_HOUR, alarmIntent);
}
 
开发者ID:ad-on-is,项目名称:chilly,代码行数:9,代码来源:RecommendationReceiver.java


注:本文中的android.app.AlarmManager.setInexactRepeating方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。