本文整理汇总了Java中android.app.AlarmManager.setAlarmClock方法的典型用法代码示例。如果您正苦于以下问题:Java AlarmManager.setAlarmClock方法的具体用法?Java AlarmManager.setAlarmClock怎么用?Java AlarmManager.setAlarmClock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.app.AlarmManager
的用法示例。
在下文中一共展示了AlarmManager.setAlarmClock方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addAlarm
import android.app.AlarmManager; //导入方法依赖的package包/类
private void addAlarm(Context context, GregorianCalendar date) {
int notificationId = new TimelessDate(date).hashCode();
Log.d("ALARM", "Scheduling alarm " + notificationId);
PendingIntent p = PendingIntent.getBroadcast(
context,
notificationId,
new Intent(context, AlarmReceiver.class),
PendingIntent.FLAG_UPDATE_CURRENT);
try {
AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
if (manager != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
manager.setAlarmClock(new AlarmManager.AlarmClockInfo(date.getTimeInMillis(), p), p);
} else {
manager.setWindow(AlarmManager.RTC_WAKEUP,
date.getTimeInMillis(),
1,
p);
}
serializeAlarm(context, notificationId);
}
} catch (SecurityException e) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
String errMSG = e.getMessage() + "\n" + sw.toString();
e.printStackTrace();
Activity act = ActivityHelper.getActivity();
if (act != null) {
ErrorDialog.newInstance("ERROR", "Failed to schedule alarm. Did some alarms crash?", errMSG)
.show(act.getFragmentManager(), "ALSECERROR");
}
}
Log.d("ALARM", "Alarm ready for "
+ " " + DateUtilities.GERMAN_STD_STIMEFORMAT.format(date.getTime())
+ DateUtilities.GERMAN_STD_SDATEFORMAT.format(date.getTime()));
}