I'm newer to android and i need to setup the event notification via broadcast receiver .
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. for example:
Prepare a Calendar
instance with future time when you want to set Aalarm:
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
Use Calancer to get time in millis.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.