Ziem My personal blog

Timer Intent

Recently, I started using KptnCook, and it’s a great cooking app with recipes changing daily.

What’s funny, it’s that it made me realize we have timer Intent in Android. When we go to the cooking steps screen, it’s embedded inside steps description:

KptnCook After clicking “20 min”, the Clock app is opened, and the timer starts.

Creating timer Intent is simple! We need to use AlarmClock.ACTION_SET_TIMER action and provide timer details:

To recreate KptnCook’s timer behavior we need:

val timerIntent = Intent(AlarmClock.ACTION_SET_TIMER).apply {
  putExtra(AlarmClock.EXTRA_LENGTH, 20 * 60) // 20 minutes
  putExtra(AlarmClock.EXTRA_SKIP_UI, true) // start timer automatically
}

Then we call startActivity(timerIntent), and that’s it.

Wait! There is one more thing… We need to add:

<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />

to the AndroidManifest.xml.

If you would like to learn more about commonly used Intents, visit Common Intents guide.