| Quick Settings Tile | Notification |
|---|---|
![]() |
![]() |
Sleep Timer helps you fall asleep while listening to music or podcasts.
When the timer stops, audio playback is gradually lowered then paused.
- Add the Tile in the Quick Settings panel.
- Tap the Tile to start a timer.
- Extend, reduce or cancel the timer with the notification actions.
Note: Don't look for a launcher icon, this app only provides a Quick Settings Tile.
You can trigger the Sleep Timer with tools like Tasker or by using adb commands:
- Start the timer
adb shell am broadcast -a fr.smarquis.sleeptimer.action.START -n fr.smarquis.sleeptimer/.SleepActionReceiver
- Start the timer with custom duration (10 min)
adb shell am broadcast -a fr.smarquis.sleeptimer.action.START -n fr.smarquis.sleeptimer/.SleepActionReceiver --el extras:duration 600
- Update the timer (-1 min)
adb shell am broadcast -a fr.smarquis.sleeptimer.action.UPDATE -n fr.smarquis.sleeptimer/.SleepActionReceiver --el extras:duration -60
- Stop the timer
adb shell am broadcast -a fr.smarquis.sleeptimer.action.STOP -n fr.smarquis.sleeptimer/.SleepActionReceiver
- Increment (default +10 min)
adb shell am broadcast -a fr.smarquis.sleeptimer.action.INCREMENT -n fr.smarquis.sleeptimer/.SleepActionReceiver
- Decrement (default -10 min)
adb shell am broadcast -a fr.smarquis.sleeptimer.action.DECREMENT -n fr.smarquis.sleeptimer/.SleepActionReceiver
- Tile and TileService: Quick Settings Tile
- Notification.Builder.setTimeoutAfter(durationMs): set notification timeout.
- Notification.Builder.setDeleteIntent(intent): set deletion action.
- NotificationCompat.Builder.setRequestPromotedOngoing(requestPromotedOngoing): request to be a promoted ongoing notification
- AudioManager.adjustStreamVolume(STREAM_MUSIC, ADJUST_LOWER, flags): lower media volume.
- AudioManager.setStreamVolume(STREAM_MUSIC, index, flags): restore initial volume.
- AudioManager.dispatchMediaKeyEvent(KeyEvent): sends a simulated key event for a media button.
Important
Android 17 introduced Background audio hardening which prevents calling AudioManager.adjustStreamVolume(streamType, direction, flags) from a background thread.
And the system does not allow PendingIntent used in Notification.Builder.setDeleteIntent(intent) to reference a foreground Service.
Therefore, an alarm must be scheduled at a precise time to trigger such foreground Service and pause audio playback.
- AlarmManager.setExactAndAllowWhileIdle(type, triggerAtMillis, PendingIntent): schedule a system alarm.
Copyright 2020 Simon Marquis
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed: in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

