本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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);
}
示例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));
}
示例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);
}
示例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);
}
}
示例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");
}
示例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();
}
}