DEV Community

myougaTheAxo
myougaTheAxo

Posted on

Android App Shortcuts — Launch Features from Home Screen

Android App Shortcuts — Launch Features from Home Screen

App shortcuts provide quick access to specific features directly from the home screen. They improve user experience and engagement. Let's explore all three types.

Static Shortcuts

Define permanent shortcuts in your manifest:

<!-- res/xml/shortcuts.xml -->
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
    <shortcut
        android:shortcutId="compose_message"
        android:enabled="true"
        android:icon="@drawable/ic_message"
        android:shortcutShortLabel="@string/compose"
        android:shortcutLongLabel="@string/compose_message">
        <intent
            android:action="android.intent.action.MAIN"
            android:targetPackage="com.example.myapp"
            android:targetClass="com.example.myapp.ComposeActivity" />
    </shortcut>
</shortcuts>
Enter fullscreen mode Exit fullscreen mode

Add to manifest:

<activity android:name=".MainActivity">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    <meta-data
        android:name="android.app.shortcuts"
        android:resource="@xml/shortcuts" />
</activity>
Enter fullscreen mode Exit fullscreen mode

Receive intent extras:

class ComposeActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        val recipientId = intent.getStringExtra("recipient_id")
        val messageText = intent.getStringExtra("message_text")

        // Handle shortcut intent
    }
}
Enter fullscreen mode Exit fullscreen mode

Dynamic Shortcuts

Create shortcuts at runtime with ShortcutManager:

val shortcutManager = getSystemService(ShortcutManager::class.java)

val shortcut = ShortcutInfo.Builder(this, "quick_reply")
    .setShortLabel("Quick Reply")
    .setLongLabel("Reply to recent messages")
    .setIcon(Icon.createWithResource(this, R.drawable.ic_reply))
    .setIntent(Intent(Intent.ACTION_VIEW).apply {
        action = "com.example.myapp.QUICK_REPLY"
        putExtra("mode", "quick")
    })
    .build()

shortcutManager.dynamicShortcuts = listOf(shortcut)
Enter fullscreen mode Exit fullscreen mode

Important: Max 4 shortcuts total (static + dynamic).

Pinned Shortcuts

Allow users to pin shortcuts themselves:

val shortcutManager = getSystemService(ShortcutManager::class.java)

if (shortcutManager.isRequestPinShortcutSupported) {
    val shortcut = ShortcutInfo.Builder(this, "settings")
        .setShortLabel("Settings")
        .setIcon(Icon.createWithResource(this, R.drawable.ic_settings))
        .setIntent(Intent(Intent.ACTION_VIEW).apply {
            action = "com.example.myapp.SETTINGS"
        })
        .build()

    shortcutManager.requestPinShortcut(shortcut, null)
}
Enter fullscreen mode Exit fullscreen mode

Best Practices

  • Icon sizes: Adaptive icons (108x108dp)
  • Label length: Short labels ≤20 chars, long labels ≤30 chars
  • Intent extras: Always include action to identify shortcut type
  • Target API 25+ for full shortcut support
  • Test on actual devices (shortcuts behave differently across launchers)

Static shortcuts provide always-available access, dynamic shortcuts adapt to usage patterns, and pinned shortcuts give users control. Combine them for optimal engagement.


Interested in mobile app development? Check out 8 Android app templates on Gumroad!

Top comments (0)