當前位置: 首頁>>代碼示例>>Java>>正文


Java AlarmManager.setAlarmClock方法代碼示例

本文整理匯總了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()));
}
 
開發者ID:dhbw-timetable,項目名稱:dhbw-timetable-android,代碼行數:40,代碼來源:AlarmSupervisor.java


注:本文中的android.app.AlarmManager.setAlarmClock方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。