简体   繁体   中英

Alarm Manager problem in time setting

I want to set an alarm at a particular date and time . iam getting my date and time with the webservice.i have parsed and splitted the date and time and used SimpleDateFormat and now i want to put this date and time in [alarmManager.set(AlarmManager.RTC_WAKEUP,dt, pendingIntent );] but my alarm doesnot work on the given time

       String str_date= hr+":"+min+":"+sec+" "+dat+"/"+mon+"/"+year;
    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss dd/MM/yyyy");
    ParsePosition position = new ParsePosition(0);

    java.util.Date stringToDate = sdf.parse(str_date, position);
     dt = stringToDate.getDate();

Please help thanks in advance

The time you should pass to Alarm.set is a long and getDate (which is deprecated ) returns an int.

Try with getTime()

AlarmManager use time in millesecond unit at UTC time zone... So time parsing have to take the timezone into account

So after SimpleDateFormat new instance you may set the UTC timezone

example :

SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss dd/MM/yyyy"); sdf.setTimeZone(TimeZone.getTimeZone("UTC"));

then your parsing will be ok and compatible for the AlarmManager service.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM