當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。