gpt4 book ai didi

java - 如何在android中每天的特定时间做某事

转载 作者:行者123 更新时间:2023-11-29 21:01:16 26 4
gpt4 key购买 nike

我想在每天上午 9:00 检查一些 url。但是我该怎么做呢?我确实检查了一些关于 AlarmManager 和 IntentService 的主题和文章,但我无法为我的应用程序聚在一起,是否有任何示例代码或其他东西?谢谢..

最佳答案

试试这个:

 /Create alarm manager

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

//Create pending intent & register it to your alarm notifier class
Intent intent = new Intent(this, AlarmReceiver_maandag_1e.class);
intent.putExtra("uur", "1e"); // if you want
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);

//set timer you want alarm to work (here I have set it to 9.00)
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 9);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);

//set that timer as a RTC Wakeup to alarm manager object
mAlarmManger .set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);

关于java - 如何在android中每天的特定时间做某事,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26048155/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com