Intent API
1. Who is the API intended for
This API is intended for individuals who want to automate their sleep related tasks as well as developers who’d like to implement apps or services integration with Sleep as Android.
You can automate most aspects of Sleep as Android and integrate it with other services or apps on your phone using common automation software such as Tasker for example.
2. Action intents to control Sleep
For actions to work via intents, you need to set com.urbandroid.sleep package on each intent.
|
com.urbandroid.sleep.alarmclock.START_SLEEP_TRACK
-
Optional extra to start in battery saving mode:
-
START_IN_BATTERY_SAVING_MODE = true
-
com.urbandroid.sleep.alarmclock.START_SLEEP_TRACK_WITH_IDEAL_ALARM_ACTION
com.urbandroid.sleep.alarmclock.STOP_SLEEP_TRACK
com.urbandroid.sleep.ACTION_PAUSE_TRACKING
com.urbandroid.sleep.alarmclock.ALARM_STATE_CHANGE
-
Extras:
-
alarm_label: String representing a label of alarm to be changed. If there are more such alarms, only one of them is going to be changed (no guarantees which).
-
alarm_enabled: Boolean saying whether alarm should be enabled or disabled.
-
alarm_id: alarm’s unique identifier (int) - retrievable from the alarm content provider.
-
com.urbandroid.sleep.alarmclock.ALARM_SNOOZE
You can send an integer extra to set the snooze duration in minutes (in range from 1 to 60).
EXTRA NAME: extra_snooze_time
com.urbandroid.sleep.alarmclock.ALARM_DISMISS_CAPTCHA
com.urbandroid.sleep.ACTION_LULLABY_STOP_PLAYBACK
com.urbandroid.sleep.REQUEST_SYNC
Starts the backup sync – export a CSV file, backup to Sleepcloud, Dropbox and Google Drive if connected. See Backup data.
Start a Service with package com.urbandroid.sleep
and class com.urbandroid.sleep.media.lullaby.LullabyService
EXTRA: extra_lullaby = “lullaby name”…
Lullaby names:
NONE, WHITENOISE, WHALE, STORM, STREAM, CAVE, FIREPLACE, SEA, WIND, CLOCK, TIBER, NIGHT, FROGS, HORSE, SHEEP, CHIMES, OM, BELLS, FLUTE, PIANO, CAT, TRAIN, MARCH, MUSICBOX, BABY, GIRL, SUB, NASA, LAVA, JUNGLE, TIBET, BABY, SCIFI, CHOR, BREATH…
3. Events emitted by Sleep
To receive the events, you need to use run-time receivers (receivers defined only in AndroidManifest.xml won’t work). Direct receiving of broadcast intents stopped working in late 2018 due to Android restrictions on implicit intents. |
com.urbandroid.sleep.alarmclock.SLEEP_TRACKING_STARTED_AUTO
com.urbandroid.sleep.alarmclock.SLEEP_TRACKING_STOPPED_AUTO
com.urbandroid.sleep.TRACKING_DEEP_SLEEP_AUTO
com.urbandroid.sleep.TRACKING_LIGHT_SLEEP_AUTO
com.urbandroid.sleep.alarmclock.ALARM_SNOOZE_CLICKED_ACTION_AUTO
com.urbandroid.sleep.alarmclock.TIME_TO_BED_ALARM_ALERT_AUTO
com.urbandroid.sleep.alarmclock.ALARM_ALERT_START_AUTO
com.urbandroid.sleep.alarmclock.ALARM_ALERT_DISMISS_AUTO
com.urbandroid.sleep.ACTION_LULLABY_START_PLAYBACK_AUTO
com.urbandroid.sleep.ACTION_LULLABY_STOPPED_PLAYBACK_AUTO
com.urbandroid.sleep.LUCID_CUE_ACTION_AUTO
Make sure Lucid dreaming is enabled in settings |
com.urbandroid.sleep.ANTISNORING_ACTION_AUTO
com.urbandroid.sleep.audio.SOUND_EVENT_AUTO
-
No more than 1 intent per 30 s gets broadcasted.
-
Extras:
-
TIMESTAMP – Unix epoch millis
-
SOUND_CLASS – one of “SNORE”, “TALK”, “COUGH”, “BABY”, “LAUGH”
-
com.urbandroid.sleep.SMART_PERIOD_AUTO