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


Java AlarmManager.setRepeating方法代码示例

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


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

示例1: start

import android.app.AlarmManager; //导入方法依赖的package包/类
public static void start(Context ctx) {
    AlarmManager manager = (AlarmManager) ctx.getSystemService("alarm");
    PendingIntent pending = PendingIntent.getBroadcast(ctx, 152, new Intent(ctx,
            SportRemindReceiver.class), 134217728);
    Helper.showLog(TAG, "SportRemindReceiver start");
    Calendar calNow = Calendar.getInstance();
    Calendar calSet = (Calendar) calNow.clone();
    calSet.setTimeInMillis(System.currentTimeMillis());
    int remindHour = 20;
    int remindMinute = 30;
    if (!TextUtil.isEmpty(OnePreference.getPrefSportRemindTime())) {
        String[] times = OnePreference.getPrefSportRemindTime().split("#");
        if (times.length == 2) {
            remindHour = Integer.parseInt(times[0]);
            remindMinute = Integer.parseInt(times[1]);
        }
    }
    calSet.set(11, remindHour);
    calSet.set(12, remindMinute);
    calSet.set(13, 0);
    calSet.set(14, 0);
    if (calSet.compareTo(calNow) <= 0) {
        calSet.add(5, 1);
    }
    manager.setRepeating(0, calSet.getTimeInMillis(), a.h, pending);
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:27,代码来源:SportRemindReceiver.java

示例2: startPollingService

import android.app.AlarmManager; //导入方法依赖的package包/类
public static void startPollingService(Context context, int seconds, Class<?> cls, String action) {
    //获取AlarmManager系统服务
    AlarmManager manager = (AlarmManager) context
            .getSystemService(Context.ALARM_SERVICE);

    //包装需要执行Service的Intent
    Intent intent = new Intent(context, cls);
    intent.setAction(action);
    PendingIntent pendingIntent = PendingIntent.getService(context, 0,
            intent, PendingIntent.FLAG_UPDATE_CURRENT);

    //触发服务的起始时间
    long triggerAtTime = SystemClock.elapsedRealtime();

    //使用AlarmManger的setRepeating方法设置定期执行的时间间隔(seconds秒)和需要执行的Service
    manager.setRepeating(AlarmManager.ELAPSED_REALTIME, triggerAtTime,
            seconds * 1000, pendingIntent);
}
 
开发者ID:8luerain,项目名称:AutoCar,代码行数:19,代码来源:PollingUtils.java

示例3: setServiceAlarm

import android.app.AlarmManager; //导入方法依赖的package包/类
public static void setServiceAlarm(Context context, boolean isOn) {
    Intent i = PollService.newIntent(context);
    PendingIntent pi = PendingIntent.getService(
            context, 0, i, 0);

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

    if (isOn) {
        alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME,
                SystemClock.elapsedRealtime(), POLL_INTERVAL_MS, pi);
    } else {
        alarmManager.cancel(pi);
        pi.cancel();
    }

    QueryPreferences.setAlarmOn(context, isOn);
}
 
开发者ID:rsippl,项目名称:AndroidProgramming3e,代码行数:19,代码来源:PollService.java

示例4: startBroadcastReceiver

import android.app.AlarmManager; //导入方法依赖的package包/类
public static void startBroadcastReceiver(Context context) {
    Log.d(TAG, "Starting Stuudium update schedulers");
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    Intent updateEvents = new Intent(context, StuudiumUpdateScheduler.class);
    updateEvents.setAction(DataUpdateService.ACTION_UPDATE_STUUDIUM);
    updateEvents.putExtra(DataUpdateService.UPDATE_STUUDIUM_EVENTS, true);
    PendingIntent updateEventsPendingIntent = PendingIntent.getBroadcast(context, 0, updateEvents, PendingIntent.FLAG_UPDATE_CURRENT);
    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), EVENT_INTERVAL, updateEventsPendingIntent);

    Intent updateOther = new Intent(context, StuudiumUpdateScheduler.class);
    updateOther.setAction(DataUpdateService.ACTION_UPDATE_STUUDIUM);
    updateOther.putExtra(DataUpdateService.UPDATE_STUUDIUM_USER, true);
    updateOther.putExtra(DataUpdateService.UPDATE_STUUDIUM_TODOS, true);
    updateOther.putExtra(DataUpdateService.UPDATE_STUUDIUM_JOURNALS, true);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 1, updateOther, PendingIntent.FLAG_UPDATE_CURRENT);
    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), OTHER_INTERVAL, pendingIntent);
}
 
开发者ID:gregoreesmaa,项目名称:minu-poska-android,代码行数:19,代码来源:StuudiumUpdateScheduler.java

示例5: onCreate

import android.app.AlarmManager; //导入方法依赖的package包/类
@Override
public void onCreate() {
    super.onCreate();
    // faz algo algumas vezes
    repeat();

    PendingIntent pintent =
            PendingIntent.getService(this, 0, new Intent(this, ServiceAfterBoot.class), 0);
    AlarmManager alarm = (AlarmManager)
            getSystemService(Context.ALARM_SERVICE);

    alarm.setRepeating(AlarmManager.RTC_WAKEUP,
            System.currentTimeMillis() , 60*1000, pintent);
}
 
开发者ID:nicolasSchirmer,项目名称:Android-Developer-Path,代码行数:15,代码来源:ServiceAfterBoot.java

示例6: getAlarmInstance

import android.app.AlarmManager; //导入方法依赖的package包/类
/**
 * 在指定延迟时间后每间隔一段时间执行
 * 
 * @param context
 * @param intent
 * @param delay
 *            延迟时间
 * @param intervalMillis
 *            间隔时间
 * @return
 */
public static AlarmManager getAlarmInstance(Context context, Intent intent,
		long delay, long intervalMillis) {
	AlarmManager manager = (AlarmManager) context
			.getSystemService(Context.ALARM_SERVICE);
	PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0,
			intent, 0);
	if (intervalMillis > 0) {
		manager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, delay,
				intervalMillis, pendingIntent);
	} else {
		manager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, delay,
				pendingIntent);
	}
	return manager;
}
 
开发者ID:SavorGit,项目名称:Hotspot-master-devp,代码行数:27,代码来源:TimerUtils.java

示例7: onReceive

import android.app.AlarmManager; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
    preferences = context.getSharedPreferences("MyBPreferences", Context.MODE_PRIVATE);
    receiveNotifications = preferences.getBoolean("receiveNotifications", false);
    notificationPeriod = preferences.getLong("notificationPeriod", 0);

    if(intent != null && intent.getAction().equals(BOOT_COMPLETED) && receiveNotifications && notificationPeriod > 0) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(notificationPeriod);
        Intent alarmIntent = new Intent(context, NotificationService.class);
        PendingIntent pendingIntent = PendingIntent.getService(context, 0, alarmIntent, 0);
        AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        manager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 60000, pendingIntent);
    }
}
 
开发者ID:kerick-jeff,项目名称:MyBP,代码行数:16,代码来源:OnBootReceiver.java

示例8: createAlarms

import android.app.AlarmManager; //导入方法依赖的package包/类
/**
 * Create alarms for all the games scheduled for today.
 */
private void createAlarms() {
    Log.i(TAG, "Creating alarms for games scheduled today");
    DatabaseContract.DbHelper dbHelper = new DatabaseContract.DbHelper(mContext);
    List<Game> gameList = dbHelper.selectUpcomingGames();
    dbHelper.close();
    for (Game game : gameList) {
        Intent gameIntent = new Intent(mContext, GameUpdateReceiver.class);
        gameIntent.putExtra("game", game.getId());
        PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, (int) game.getId(), gameIntent, PendingIntent.FLAG_CANCEL_CURRENT);
        long interval = game.getLeagueType().getRefreshInterval() * 60 * 1000L;
        AlarmManager manager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
        manager.setRepeating(AlarmManager.RTC_WAKEUP, new DateTime(game.getGameDateTime(), VEGAS_TIME_ZONE).getMillis(), interval, pendingIntent);
    }
}
 
开发者ID:riteshakya037,项目名称:Android-Scrapper,代码行数:18,代码来源:UpdateReceiver.java

示例9: startPolling

import android.app.AlarmManager; //导入方法依赖的package包/类
/**
 * 开启轮询
 */
@TargetApi(Build.VERSION_CODES.CUPCAKE)
public static void startPolling(Context context, int mills, PendingIntent pendingIntent) {
    AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    manager.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime(),
            mills, pendingIntent);
}
 
开发者ID:jqjm,项目名称:Liteframework,代码行数:10,代码来源:PollingUtil.java

示例10: setServiceAlarm

import android.app.AlarmManager; //导入方法依赖的package包/类
public static void setServiceAlarm(Context context, boolean isOn) {
    Intent i = PollService.newIntent(context);
    PendingIntent pi = PendingIntent.getService(context, 0, i, 0);
    AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);

    if (isOn) {
        alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime(),
                POLL_INTERVAL_MS, pi);
    } else {
        alarmManager.cancel(pi);
        pi.cancel();
    }

    QueryPreferences.setAlarmOn(context, isOn);
}
 
开发者ID:ivicel,项目名称:Android-Programming-BigNerd,代码行数:16,代码来源:PollService.java

示例11: onEnabled

import android.app.AlarmManager; //导入方法依赖的package包/类
@Override
public void onEnabled(Context context) {
    super.onEnabled(context);
    AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    long intervalWeather = 7200000;

    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());

    alarmMgr.setRepeating(AlarmManager.RTC, calendar.getTimeInMillis(),
            intervalWeather, createWeatherUpdateIntent(context));
}
 
开发者ID:SEALiu,项目名称:Calendouer,代码行数:13,代码来源:WeatherWidgetProvider.java

示例12: startBroadcast

import android.app.AlarmManager; //导入方法依赖的package包/类
/**
 * 每隔5秒发送一次广播
 */
private void startBroadcast() {
    //创建Alarm并启动
    Intent intent = new Intent("LOCATION_CLOCK");
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
    AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    // 每五秒唤醒一次
    long second = 5 * 1000;
    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), second, pendingIntent);
}
 
开发者ID:zhuyu1022,项目名称:amap,代码行数:13,代码来源:MapService.java

示例13: onUpdate

import android.app.AlarmManager; //导入方法依赖的package包/类
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    final int count = appWidgetIds.length;
    final AlarmManager m = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    final Calendar TIME = Calendar.getInstance();

    for (int i = 0; i < count; i++) {

        TIME.set(Calendar.MINUTE, 0);
        TIME.set(Calendar.SECOND, 0);
        TIME.set(Calendar.MILLISECOND, 0);
        Intent in = new Intent(context, WidgetUpdateService.class);

        if (service == null) {
            service = PendingIntent.getService(context, 0, in, PendingIntent.FLAG_CANCEL_CURRENT);
        }

        m.setRepeating(AlarmManager.RTC, TIME.getTime().getTime(), LONG_UPDATE, service);

        // ---------
        int widgetId = appWidgetIds[i];

        RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.main_widget);
        Intent intent = new Intent(context, MyWidgetProvider.class);

        intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
        intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);

        PendingIntent pendingIntent = PendingIntent.getBroadcast(
                context, widgetId, intent, PendingIntent.FLAG_UPDATE_CURRENT
        );
        remoteViews.setOnClickPendingIntent(R.id.wFeedtitlesLayout, pendingIntent);
        appWidgetManager.updateAppWidget(widgetId, remoteViews);
    }
}
 
开发者ID:no-go,项目名称:AnotherRSS,代码行数:36,代码来源:MyWidgetProvider.java

示例14: startUpdate

import android.app.AlarmManager; //导入方法依赖的package包/类
public void startUpdate() {
    // Retrieve a PendingIntent that will perform a broadcast
    Intent updateIntent = new Intent(this, RatesUpdateReceiver.class);
    updateIntent.putExtra("Cryptos", cryS)
            .putExtra("Currencies", currS);
    pendingIntent = PendingIntent.getBroadcast(this, 1, updateIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    int interval = 10000;

    manager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), interval, pendingIntent);
    Log.d(TAG, "Update Alarm started");
}
 
开发者ID:EseCoder,项目名称:cryptotracker,代码行数:14,代码来源:HomeActivity.java

示例15: onCreate

import android.app.AlarmManager; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_scrolling);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent i = new Intent(ScrollingActivity.this,MainActivity.class);
            startActivity(i);
        }
    });


    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    if (!prefs.getBoolean("firstTime", false)) {

        Intent alarmIntent = new Intent(this, AlarmReciever.class);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, alarmIntent, 0);

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

        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(System.currentTimeMillis());
        calendar.set(Calendar.HOUR_OF_DAY, 6);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 1);

        manager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
                AlarmManager.INTERVAL_DAY, pendingIntent);

        SharedPreferences.Editor editor = prefs.edit();
        editor.putBoolean("firstTime", true);
        editor.apply();
    }

}
 
开发者ID:gigabytedevelopers,项目名称:Oremus,代码行数:41,代码来源:ScrollingActivity.java


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