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. As an example of what you can do please follow Jeoren's guide on how to Let Google Text to Speech say on which time your alarm goes.
ACTION
Sleep tracking start intent
com.urbandroid.sleep.alarmclock.START_SLEEP_TRACK
Optional EXTRA to start in battery saving mode: START_IN_BATTERY_SAVING_MODE = true
Sleep tracking stop intent
com.urbandroid.sleep.alarmclock.STOP_SLEEP_TRACK
Snooze Alarm
com.urbandroid.sleep.alarmclock.ALARM_SNOOZE
Dismiss Alarm
com.urbandroid.sleep.alarmclock.ALARM_DISMISS_CAPTCHA
Lullaby Stop
com.urbandroid.sleep.ACTION_LULLABY_STOP_PLAYBACK
start a Service with package "com.urbandroid.sleep" and class "com.urbandroid.sleep.media.lullaby.LullabyService"
EXTRA: extra_lullaby = "lullaby name"...
Lullaby names:
NONE, WHALE, STORM, STREAM, CAVE, FIREPLACE, SEA, WIND, CLOCK, TIBER, NIGHT, FROGS, HORSE, SHEEP, CHIMES, OM, BELLS, FLUTE, PIANO, CAT, TRAIN, MARCH, MUSICBOX, BABY, GIRL...
EVENTS
Sleep tracking started
com.urbandroid.sleep.alarmclock.SLEEP_TRACKING_STARTED
Sleep tracking stopped
com.urbandroid.sleep.alarmclock.SLEEP_TRACKING_STOPPED
Snoozed by user
com.urbandroid.sleep.alarmclock.ALARM_SNOOZE_CLICKED_ACTION
Time to bed notification
com.urbandroid.sleep.alarmclock.TIME_TO_BED_ALARM_ALERT
Alarm triggered
Alarm dismissed
Lucid dreaming cue:
com.urbandroid.sleep.LUCID_CUE_ACTION NOTE: enable settings-lucid dreaming
Antisnoring sound:
com.urbandroid.sleep.ANTISNORING_ACTION
com.urbandroid.sleep.alarmclock.AUTO_START_SLEEP_TRACK
Using Tasker with Sleep as Android
React on Sleep as Android events in Tasker Event -> System -> Intent (previously Misc -> Intent received) and add one of the Intents described above.
For example you can start you weather app when alarm is dismissed, by listening for the com.urbandroid.sleep.alarmclock.ALARM_ALERT_DISMISS intent.
Start an Sleep as Android action from Tasker
Event -> System -> Intent (previously Misc -> Intent send)
For example, create a new task, click + and choose "Action Intent" from the Misc category and there you fill in com.urbandroid.sleep.alarmclock.START_SLEEP_TRACK into the action text field. So you can start sleep tracking when you plug your phone to charger for example.
android.intent.action.SET_ALARM
EXTRA_MESSAGE = "android.intent.extra.alarm.MESSAGE";
EXTRA_HOUR = "android.intent.extra.alarm.HOUR";
EXTRA_MINUTES = "android.intent.extra.alarm.MINUTES";
EXTRA_SKIP_UI = "android.intent.extra.alarm.SKIP_UI";
"alarm_enabled": Boolean saying whether alarm should be enabled or disabled.Enabling/disabling alarm by label 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). Tip: use Reactor to handle Sleep as Android Intents. As an example the following Reactor Script starts a news Reader after you dismiss the alarm to synchronize latest latest news:
The following script will start FM Radio as your alarm using (FMAlarm) you can setup an alarm with silnce ringtone and no vibration and let Reactor start FMAlarm after the alarm triggers.
Reactor is for FREE is you use one script at a time. For more Reactor script for Sleep as Android, please have a look here.
Sleep data content provider:
1. Use the following class to access the content provider
public class Record {
public static final String AUTHORITY = "com.urbandroid.sleep.history";
public static final String RECORDS_TABLE = "records";
public static class Records implements BaseColumns {
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/" + RECORDS_TABLE);
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/com.urbandroid.sleep.history";
public static final String RECORD_ID = "_id";
public static final String START_TIME = "startTime";
public static final String LATEST_TO_TIME = "latestToTime";
public static final String TO_TIME = "toTime";
public static final String FRAMERATE = "framerate";
public static final String RATING = "rating";
public static final String COMMENT = "comment";
public static final String RECORD_DATA = "recordData";
public static final String LEN_ADJUST = "lenAdjust"; }
}
2. Query the content provider (only select is currently supporter - no update or delete)
private final String[] projection = new String[] { Record.Records.START_TIME,Record.Records.TO_TIME, Record.Records.RATING};
Cursor cursor = activity.managedQuery(Record.Records.CONTENT_URI, projection, Record.Records.START_TIME + " > " + yearAgo, null, Record.Records.START_TIME + " ASC");
Alarm data content provider:
Alarm content provider allows all provider operations.
public final class Alarm {
public static class Columns implements BaseColumns {
public static final Uri CONTENT_URI = Uri.parse("content://com.urbandroid.sleep.alarmclock/alarm");
public static final String HOUR = "hour";
public static final String MINUTES = "minutes";
public static final String DAYS_OF_WEEK = "daysofweek";
public static final String ALARM_TIME = "alarmtime";
public static final String SUSPEND_TIME = "suspendtime";
public static final String NON_DEEPSLEEP_WAKEUP_WINDOWN = "ndswakeupwindow";
public static final String ENABLED = "enabled";
public static final String VIBRATE = "vibrate";
public static final String MESSAGE = "message";
public static final String ALERT = "alert";
public static final String DEFAULT_SORT_ORDER = HOUR + ", " + MINUTES + " ASC";
public static final int ALARM_ID_INDEX = 0;
public static final int ALARM_HOUR_INDEX = 1;
public static final int ALARM_MINUTES_INDEX = 2;
public static final int ALARM_DAYS_OF_WEEK_INDEX = 3;
public static final int ALARM_TIME_INDEX = 4;
public static final int ALARM_ENABLED_INDEX = 5;
public static final int ALARM_VIBRATE_INDEX = 6;
public static final int ALARM_MESSAGE_INDEX = 7;
public static final int ALARM_ALERT_INDEX = 8;
public static final int ALARM_SUSPEND_TIME_INDEX = 9;
public static final int ALARM_NON_DEEPSLEEP_WAKEUP_WINDOW_INDEX = 10;
}
}
Starting sleep tracking from another process
intent.setAction("com.urbandroid.sleep.alarmclock.START_SLEEP_TRACK"); intent.putExtra("START_AIRPLANE", true); intent.setClassName("com.urbandroid.sleep", "com.urbandroid.sleep.alarmclock.StartTrackReceiver"); sendBroadcast(intent); |
Documentation >