[英]How can i pass the future Time to Wake up the Pending Intent?
I'm newer to android and i need to setup the event notification via broadcast receiver . 我是android的新手,我需要通过广播接收器设置事件通知。
For now i'm passing the hard coded Time to get the Notification it's working properly... How can i pass the some future time to get the notification at that time... 现在,我正在通过硬编码的时间来获取通知,它正在正常工作...我该如何在将来的某个时间里花时间来获取通知...
Tried Code: 试过的代码:
EditText text = (EditText) findViewById(R.id.editText1);
int time = Integer.parseInt(text.getText().toString());
Intent intent = new Intent(this, MyReceiver.class);
PendingIntent pend_intent = PendingIntent.getBroadcast(
this.getApplicationContext(), 0, intent, 0);
//calls the alarm
AlarmManager alarmManager = (AlarmManager) getSystemService(
ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()
+ (time * 10000), pend_intent);
Use Calendar.getInstance()
to set future time for AlarmManager. 使用Calendar.getInstance()
设置AlarmManager的未来时间。 for example: 例如:
Prepare a Calendar
instance with future time when you want to set Aalarm: 当您想要设置Aalarm时,准备一个带有将来时间的Calendar
实例:
public Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, hour);
cal.set(Calendar.MINUTE, minutes);
cal.set(Calendar.DAY_OF_MONTH, day);
cal.set(Calendar.MONTH, month) - 1);
cal.set(Calendar.YEAR, year);
Now pass cal.getTimeInMillis()
as second parameter instead of System.currentTimeMillis()+ (time * 10000)
in alarmManager.set
现在,将cal.getTimeInMillis()
作为第二个参数而不是cal.getTimeInMillis()
的System.currentTimeMillis()+ (time * 10000)
alarmManager.set
Use Calancer to get time in millis. 使用Calancer来获取以毫秒为单位的时间。
For eg 例如
Calendar mCalendar = Calendar.getInstance();
mCalendar.setTimeInMillis(System.currentTimeMillis());
Now into you Alarm manager set method, Use Set Method like this. 现在,进入警报管理器设置方法,使用像这样的设置方法。
mAlarmManager.set(AlarmManager.RTC_WAKEUP, mCalendar.getTimeInMillis()
+ mTime * 10000, mPendingIntent);
Hope It Helps Cheers -Aman 希望能帮助加油-阿曼
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.