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