Java Code Examples for android.app.AlarmManager#getNextAlarmClock()
The following examples show how to use
android.app.AlarmManager#getNextAlarmClock() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ZenModeConfig.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
private static long getNextAlarm(Context context) { final AlarmManager alarms = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); final AlarmManager.AlarmClockInfo info = alarms.getNextAlarmClock(context.getUserId()); return info != null ? info.getTriggerTime() : 0; }
Example 2
Source File: NextAlarmUpdaterJob.java From hassalarm with MIT License | 4 votes |
/** * Create a call that can be executed. Will throw an exception in case of any failure, * like missing parameters etc. */ public static Request createRequest(Context context, String host, String apiKeyOrToken, String entityId, Constants.AccessType accessType, boolean entityIdIsLegacy) throws IllegalArgumentException { final AlarmManager alarmManager = context.getSystemService(AlarmManager.class); final AlarmManager.AlarmClockInfo alarmClockInfo = alarmManager.getNextAlarmClock(); // Verify host and API key. if (TextUtils.isEmpty(host)) { throw new IllegalArgumentException("Host is missing. You need to specify the host to your hass.io instance."); } // No port number? Add default one. if (!host.contains(":")) { host = String.format(Locale.US, "%s:%d", host, DEFAULT_PORT); } // Default to http:// if there is no protocol defined. if (!host.startsWith("http://") && !host.startsWith("https://")) { host = String.format(Locale.US, "http://%s", host); } // Support empty API key, if there is no one required. final Retrofit retrofit = new Retrofit.Builder() .baseUrl(host) .addConverterFactory(GsonConverterFactory.create()) .build(); final HassApi hassApi = retrofit.create(HassApi.class); // Get next scheduled alarm, if any. final State state; final Datetime datetime; final long triggerTimestamp; if (alarmClockInfo != null) { triggerTimestamp = alarmClockInfo.getTriggerTime(); final Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(triggerTimestamp); state = new State(DATE_FORMAT_LEGACY.format(calendar.getTime())); datetime = new Datetime(entityId, DATE_FORMAT.format(calendar.getTime())); } else { triggerTimestamp = 0; state = new State(""); datetime = new Datetime(entityId, "1970-01-01 00:00:00"); } Log.d(Constants.LOG_TAG, "Setting time to " + datetime.datetime); // Enqueue call and run on background thread. // Check if it is using long lived access tokens final Call<ResponseBody> call; if (accessType == Constants.AccessType.LONG_LIVED_TOKEN) { // Create Authorization Header value String bearer = String.format(BEARER_PATTERN, apiKeyOrToken); if (entityIdIsLegacy) { call = hassApi.updateStateUsingToken(state, entityId, bearer); } else { call = hassApi.setInputDatetimeUsingToken(datetime, bearer); } } else { if (accessType == Constants.AccessType.WEB_HOOK) { call = hassApi.updateStateUsingWebhook(datetime, apiKeyOrToken); } else if (entityIdIsLegacy) { call = hassApi.updateStateUsingApiKey(state, entityId, apiKeyOrToken); } else { call = hassApi.setInputDatetimeUsingApiKey(datetime, apiKeyOrToken); } } return Request.create(call, triggerTimestamp); }
Example 3
Source File: MainActivity.java From hassalarm with MIT License | 4 votes |
private long getTriggerTime() { final AlarmManager alarmManager = getSystemService(AlarmManager.class); final AlarmManager.AlarmClockInfo nextAlarm = alarmManager.getNextAlarmClock(); return nextAlarm == null ? -1 : nextAlarm.getTriggerTime(); }
Example 4
Source File: NextAlarmClockBroadcastReceiver.java From PhoneProfilesPlus with Apache License 2.0 | 4 votes |
@Override public void onReceive(Context context, Intent intent) { //PPApplication.logE("##### NextAlarmClockBroadcastReceiver.onReceive", "xxx"); //CallsCounter.logCounter(context, "NextAlarmClockBroadcastReceiver.onReceive", "NextAlarmClockBroadcastReceiver_onReceive"); if (intent == null) return; //if (!PPApplication.getApplicationStarted(context.getApplicationContext(), true)) // return; //if (android.os.Build.VERSION.SDK_INT >= 21) { String action = intent.getAction(); if ((action != null) && action.equals(AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED)) { AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); if (alarmManager != null) { AlarmManager.AlarmClockInfo alarmClockInfo = alarmManager.getNextAlarmClock(); if (alarmClockInfo != null) { long _time = alarmClockInfo.getTriggerTime(); /*if (PPApplication.logEnabled()) { SimpleDateFormat sdf = new SimpleDateFormat("EE d.MM.yyyy HH:mm:ss:S"); String result = sdf.format(_time); PPApplication.logE("NextAlarmClockBroadcastReceiver.onReceive", "_time=" + result); }*/ PendingIntent infoPendingIntent = alarmClockInfo.getShowIntent(); // infoPendingIntent == null - Xiaomi Clock :-/ // infoPendingIntent == null - LG Clock :-/ // infoPendingIntent == null - Huawei Clock :-/ if (infoPendingIntent != null) { String packageName = infoPendingIntent.getCreatorPackage(); //PPApplication.logE("NextAlarmClockBroadcastReceiver.onReceive", "packageName=" + packageName); if (packageName != null) { if (!packageName.equals(context.getPackageName())) { //PPApplication.logE("NextAlarmClockBroadcastReceiver.onReceive", "packageName=" + packageName); // com.google.android.deskclock - Google Clock // com.sec.android.app.clockpackage - Samsung Clock // com.sonyericsson.organizer - Sony Clock // com.amdroidalarmclock.amdroid - AMdroid // com.alarmclock.xtreme.free - Alarm Clock XTreme free // com.alarmclock.xtreme - Alarm Clock XTreme // droom.sleepIfUCan - Alarmy (Sleep if u can) // com.funanduseful.earlybirdalarm - Early Bird Alarm Clock // com.apalon.alarmclock.smart - Good Morning Alarm Clock // com.kog.alarmclock - I Can't Wake Up! Alarm Clock // com.urbandroid.sleep - Sleep as Android // ch.bitspin.timely - Timely // com.angrydoughnuts.android.alarmclock - Alarm Klock /*if (packageName.equals("com.google.android.deskclock") || packageName.equals("com.sec.android.app.clockpackage") || packageName.equals("com.sonyericsson.organizer") || packageName.equals("com.amdroidalarmclock.amdroid") || packageName.equals("com.alarmclock.xtreme") || packageName.equals("com.alarmclock.xtreme.free") || packageName.equals("droom.sleepIfUCan") || packageName.equals("com.funanduseful.earlybirdalarm") || packageName.equals("com.apalon.alarmclock.smart") || packageName.equals("com.kog.alarmclock") || packageName.equals("com.urbandroid.sleep") || packageName.equals("ch.bitspin.timely") || packageName.equals("com.angrydoughnuts.android.alarmclock"))*/ setAlarm(_time, packageName, alarmManager, context); } } /*else { //PPApplication.logE("NextAlarmClockBroadcastReceiver.onReceive", "packageName == null"); setAlarm(_time, "", alarmManager, context); }*/ } /*else { //PPApplication.logE("NextAlarmClockBroadcastReceiver.onReceive", "infoPendingIntent == null"); setAlarm(_time, "", alarmManager, context); }*/ } //else { //PPApplication.logE("NextAlarmClockBroadcastReceiver.onReceive", "alarmClockInfo == null"); //removeAlarm(alarmManager, context); //} } } //} }