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


Java AlarmManager类代码示例

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


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

示例1: setAlarm

import android.app.AlarmManager; //导入依赖的package包/类
public static void setAlarm(Context context, long waitTimeMillis) {
  Intent        intent        = new Intent(context, ExpirationListener.class);
  PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
  AlarmManager  alarmManager  = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);

  alarmManager.cancel(pendingIntent);
  alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + waitTimeMillis, pendingIntent);
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:9,代码来源:ExpirationListener.java

示例2: 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

示例3: pushLocalNotification

import android.app.AlarmManager; //导入依赖的package包/类
public void pushLocalNotification( float fireTimeOffsetS, String title, String message, String data )
{
	//Log.i("yoyo", "local notifcation scheduled in " + fireTimeOffsetS + " seconds");
	Context appContext = mContext.getApplicationContext();
	Intent intent = new Intent( appContext, PushLocalAlarmReceiver.class);
	intent.putExtra( KEY_NTF_TITLE, title );
	intent.putExtra( KEY_NTF_MESSAGE, message );
	intent.putExtra( KEY_NTF_DATA, data);
	
	//problems stacking multiple alarms...try this??
	long timeMilli = System.currentTimeMillis() + (long)(fireTimeOffsetS*1000);
	int uniqueID = (int)timeMilli;
	PendingIntent pendingIntent = PendingIntent.getBroadcast(appContext, uniqueID, intent, PendingIntent.FLAG_ONE_SHOT);
	AlarmManager am = (AlarmManager)appContext.getSystemService(Context.ALARM_SERVICE);
	
	am.set(AlarmManager.RTC_WAKEUP, timeMilli, pendingIntent);
	
	//store details of alarm - so it can be cancelled
	storePendingLocalAlarm( title, message, data, timeMilli );
	
}
 
开发者ID:Magicrafter13,项目名称:1946,代码行数:22,代码来源:GcmPush.java

示例4: scheduleSync

import android.app.AlarmManager; //导入依赖的package包/类
private void scheduleSync(Context context, int syncJitter) {
    int jitterMillis = (int) (RANDOM.nextFloat() * syncJitter);
    final String debugMessage = "Scheduling next sync for " + jitterMillis + "ms";
    LOGI(TAG, debugMessage);

    ((AlarmManager) context.getSystemService(Context.ALARM_SERVICE))
            .set(
                    AlarmManager.RTC,
                    System.currentTimeMillis() + jitterMillis,
                    PendingIntent.getBroadcast(
                            context,
                            0,
                            new Intent(context, TriggerSyncReceiver.class),
                            PendingIntent.FLAG_CANCEL_CURRENT));

}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:17,代码来源:SyncCommand.java

示例5: setclickalarm

import android.app.AlarmManager; //导入依赖的package包/类
public void setclickalarm(int id) {

		int requestCode = 0;

		requestCode = idValue;
		// ---------------------------------------------------------------------
		AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
		Intent intent = new Intent(List.alist, ClockActivity.class);
		intent.putExtra("content", contentValue);// ��������
		intent.putExtra("alarmtime", alarmValue);// ��������ʱ��
		PendingIntent pi = PendingIntent.getActivity(List.alist, requestCode,
				intent, PendingIntent.FLAG_CANCEL_CURRENT); // ����id���ò�ͬ������
		Calendar alarmTime = Calendar.getInstance();
		long alarmdatetime = changedatetime(alarmValue); // ��ʱ��ת��Ϊlong��
		alarmManager.set(AlarmManager.RTC_WAKEUP, alarmdatetime, pi);
		Toast.makeText(getApplicationContext(), "�������ú���", Toast.LENGTH_LONG)
				.show();
	}
 
开发者ID:z9961,项目名称:DoList,代码行数:19,代码来源:EditActivity.java

示例6: initAlarm

import android.app.AlarmManager; //导入依赖的package包/类
private void initAlarm(Context context, String serviceName){
	if(mAlarmManager == null){
           mAlarmManager = ((AlarmManager)context.getSystemService(Context.ALARM_SERVICE));
       }
       if(mPendingIntent == null){
           Intent intent = new Intent();
   		ComponentName component = new ComponentName(context.getPackageName(), serviceName);
   		intent.setComponent(component);
           intent.setFlags(Intent.FLAG_EXCLUDE_STOPPED_PACKAGES);
           mPendingIntent = PendingIntent.getService(context, 0, intent, 0);
       }
       mAlarmManager.cancel(mPendingIntent);
}
 
开发者ID:paozhuanyinyu,项目名称:FreshMember,代码行数:14,代码来源:DaemonStrategyUnder21.java

示例7: setAlarm

import android.app.AlarmManager; //导入依赖的package包/类
/**
 * Set an alarm to silence the phone.
 *
 * @param startTimeInMillis The time at which phone is to be shushed
 * @param endTimeInMillis   The time at which phone is to be un-shushed
 */
public void setAlarm(long startTimeInMillis, long endTimeInMillis) {
    if (startTimeInMillis >= endTimeInMillis) {
        return;
    }
    alarmManager.set(
            AlarmManager.RTC_WAKEUP,
            startTimeInMillis,
            getDefaultPendingIntent(true)
    );
    alarmManager.set(
            AlarmManager.RTC_WAKEUP,
            endTimeInMillis,
            getDefaultPendingIntent(false)
    );
}
 
开发者ID:samagra14,项目名称:Shush,代码行数:22,代码来源:AlarmScheduler.java

示例8: setAlarm

import android.app.AlarmManager; //导入依赖的package包/类
private void setAlarm(Calendar targetCal) {
//        Calendar calNow = ;
        long timeInMilis = targetCal.getTimeInMillis() - Calendar.getInstance().getTimeInMillis();
        long seconds = timeInMilis / 1000;
        long minutes = seconds / 60;
        long hours = minutes / 60;
        String time = hours % 24 + " hours," + minutes % 60 + " minutes," + seconds % 60 + " seconds";


        Toast.makeText(getApplicationContext(), "Alarm set to " + (time) + " from now", Toast.LENGTH_LONG).show();

        Intent intent = new Intent(getBaseContext(), AlarmReceiver.class);
        intent.putExtra(Constants.EXTRA_DEVICE, device);
        intent.putExtra(Constants.STATE_DEVICE, buttons_state);
//        Log.d("mmeessaaggee","buttons alarm state  "+buttons_state);
        AppUtils.saveAlarmState(getApplicationContext(), Constant.BUTTON_ALARM_STATE, buttons_state);

        PendingIntent pendingIntent = PendingIntent.getBroadcast(
                getBaseContext(), RQS_1, intent, 0);
        AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
        alarmManager.set(AlarmManager.RTC_WAKEUP, targetCal.getTimeInMillis(),
                pendingIntent);

    }
 
开发者ID:bilal-rashid,项目名称:Lazy-Switches,代码行数:25,代码来源:BluetoothActivity.java

示例9: scheduleUpdate

import android.app.AlarmManager; //导入依赖的package包/类
private static void scheduleUpdate(Context context) {
    /*
     schedule updates via AlarmManager, because we don't want to wake the device on every update
     see https://developer.android.com/guide/topics/appwidgets/index.html#MetaData
     */
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    PendingIntent intent = getAlarmIntent(context);
    alarmManager.cancel(intent);

    /* repeat after every full hour because results of search can change on new day
        because of timezones repeat every hour instead of every day */
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.add(Calendar.HOUR_OF_DAY, 1);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 1);
    alarmManager.setInexactRepeating(AlarmManager.RTC, calendar.getTimeInMillis(), AlarmManager.INTERVAL_HOUR, intent);
}
 
开发者ID:orgzly,项目名称:orgzly-android,代码行数:20,代码来源:ListWidgetProvider.java

示例10: onStartCommand

import android.app.AlarmManager; //导入依赖的package包/类
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    updateWeather();
    updateBingPic();
    AlarmManager manager = (AlarmManager) getSystemService(ALARM_SERVICE);
    int anHour = 4 * 60 * 60 * 1000;//4个小时的毫秒数
    long triggerAtTime = SystemClock.elapsedRealtime() + anHour;
    Intent i = new Intent(this, AutoUpdateService.class);
    PendingIntent pi = PendingIntent.getService(this, 0, i, 0);
    manager.cancel(pi);
    manager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerAtTime, pi);
    return super.onStartCommand(intent, flags, startId);
}
 
开发者ID:zhegeshijiehuiyouai,项目名称:Weather365,代码行数:14,代码来源:AutoUpdateService.java

示例11: onCreate

import android.app.AlarmManager; //导入依赖的package包/类
/**
 * Initializes the service when it is first created
 */
@Override
public void onCreate() {
    super.onCreate();
    if (Constants.LOGVV) {
        Log.v(Constants.TAG, "Service onCreate");
    }

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

    mUpdateThread = new HandlerThread(TAG + "-UpdateThread");
    mUpdateThread.start();
    mUpdateHandler = new Handler(mUpdateThread.getLooper(), mUpdateCallback);

    mNotifier = new DownloadNotifier(this);
    mNotifier.cancelAll();

    mObserver = new DownloadManagerContentObserver();
    getContentResolver().registerContentObserver(Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI,
            true, mObserver);

}
 
开发者ID:limpoxe,项目名称:Android-DownloadManager,代码行数:25,代码来源:DownloadService.java

示例12: deleteAllReminders

import android.app.AlarmManager; //导入依赖的package包/类
/**
 * Delete the all reminders
 * @param context - the current app context
 */
public void deleteAllReminders(Context context) {
    AlarmManager am = (AlarmManager) context.getSystemService(ALARM_SERVICE);
    for (int i = 0; i < mPlantsNumber; i++) {
        PendingIntent pendingIntent = PendingIntent.getBroadcast(context, i, new Intent(context, BirthdayReceiver.class), 0);
        if (am != null) {
            am.cancel(pendingIntent);
            pendingIntent = PendingIntent.getBroadcast(context, i, new Intent(context, FertilizerReceiver.class), 0);
            am.cancel(pendingIntent);
            pendingIntent = PendingIntent.getBroadcast(context, i, new Intent(context, HeightMeasureReceiver.class), 0);
            am.cancel(pendingIntent);
            pendingIntent = PendingIntent.getBroadcast(context, i, new Intent(context, UpdatePhotoReceiver.class), 0);
            am.cancel(pendingIntent);
            pendingIntent = PendingIntent.getBroadcast(context, i, new Intent(context, WaterReceiver.class), 0);
            am.cancel(pendingIntent);
        }
    }
}
 
开发者ID:iskandergaba,项目名称:Botanist,代码行数:22,代码来源:DatabaseManager.java

示例13: setBirthdayReminder

import android.app.AlarmManager; //导入依赖的package包/类
/**
 * Set when to remind about birthdays
 * @param context - the current app context
 * @param plant - the plant whose birthday is reminded of
 * @param id - the id of the plant
 */
public void setBirthdayReminder(Context context, Plant plant, int id) {
    Intent intent = new Intent(context, BirthdayReceiver.class);
    intent.putExtra("name", plant.getName());
    intent.putExtra("species", plant.getSpecies());
    intent.putExtra("birthday", plant.getBirthday());
    intent.putExtra("id", id);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, id, intent, 0);
    Calendar now = Calendar.getInstance();
    now.setTimeInMillis(System.currentTimeMillis());
    Calendar birthday = Calendar.getInstance();
    birthday.setTimeInMillis(plant.getBirthday());
    birthday.set(Calendar.YEAR, now.get((Calendar.YEAR)));
    if (birthday.getTimeInMillis() < now.getTimeInMillis()) {
        birthday.set(Calendar.YEAR, now.get((Calendar.YEAR)) + 1);
    }
    AlarmManager am = (AlarmManager)context.getSystemService(ALARM_SERVICE);
    if (am != null) {
        am.set(AlarmManager.RTC_WAKEUP, birthday.getTimeInMillis(), pendingIntent);
    }
}
 
开发者ID:iskandergaba,项目名称:Botanist,代码行数:27,代码来源:DatabaseManager.java

示例14: setAlarmEnableAirplaneMode

import android.app.AlarmManager; //导入依赖的package包/类
public void setAlarmEnableAirplaneMode(Context context)
{
    Log.d(TAG, "setAlarmEnableAirplaneMode");
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
    String enableAutoAirplaneMode = settings.getString(Constants.ENABLE_AIRPLANE_TIME, "23:00");

    String[] enable = enableAutoAirplaneMode.split(":");

    Calendar now = Calendar.getInstance();
    Calendar calendarStart = Calendar.getInstance();
    now.setTimeInMillis(System.currentTimeMillis());
    calendarStart.setTimeInMillis(now.getTimeInMillis());

    calendarStart.set(Calendar.HOUR_OF_DAY, Integer.valueOf(enable[0]));
    calendarStart.set(Calendar.MINUTE, Integer.valueOf(enable[1]));
    calendarStart.set(Calendar.SECOND, 0);
    calendarStart.set(Calendar.MILLISECOND, 0);

    Intent intentEnable = new Intent(context, AlarmBroadcastReceiver.class);
    intentEnable.putExtra(Constants.ID, Constants.ID_ENABLE);

    enableAirplaneModePendingIntent = PendingIntent.getBroadcast(context, Constants.ID_ENABLE, intentEnable, 0);
    alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, calendarStart.getTimeInMillis(), enableAirplaneModePendingIntent);
    setAlarmAfterReboot(context, true);
}
 
开发者ID:MBach,项目名称:AutoAirplaneMode,代码行数:27,代码来源:AlarmBroadcastReceiver.java

示例15: onReceive

import android.app.AlarmManager; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
  long          scheduledTime = getNextScheduledExecutionTime(context);
  AlarmManager  alarmManager  = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
  Intent        alarmIntent   = new Intent(context, getClass());
  PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, 0);

  if (System.currentTimeMillis() >= scheduledTime) {
    scheduledTime = onAlarm(context, scheduledTime);
  }

  Log.w(TAG, getClass() + " scheduling for: " + scheduledTime);

  alarmManager.cancel(pendingIntent);
  alarmManager.set(AlarmManager.RTC_WAKEUP, scheduledTime, pendingIntent);
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:17,代码来源:PersistentAlarmManagerListener.java


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