我想設置alarms 功能,我把時間存儲在一個cvs文件中。格式是hh:mm,如02:13。我想在這個時間點設置鬧鐘。
SimpleDateFormat dt = new SimpleDateFormat("hh:mm");
dt.parse(str); // GET TIME HERE
NotificationManager manger = (NotificationManager) this.getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.launcher, "Mosque Prayer Times", time);
PendingIntent contentIntent = PendingIntent.getActivity(this.getActivity(), 0, new Intent(this.getActivity(), AlarmReceiver.class), 0);
notification.setLatestEventInfo(this.getActivity(), name, title, contentIntent);
notification.flags = Notification.FLAG_INSISTENT;
notification.sound = Uri.parse("android.resource://com.trib.app.mosqueprayertimes/raw/adhan.mp3");
manger.notify(id, notification);
}
我如何從date 格式中提取時間然後在通知中設置?
AlarmManager am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
SimpleDateFormat dt = new SimpleDateFormat("hh:mm");
Date date = new Date(); //當前時間日期
try {
Date dateTime = dt.parse(str);
date.setHours(dateTime.getHours());
date.setMinutes(dateTime.getMinutes());
} catch (ParseException e) {
e.printStackTrace();
}
am.set(AlarmManager.RTC_WAKEUP,date.getTime(), contentIntent);