Shortbread
Android library that generates app shortcuts for activities and methods annotated with @Shortcut. No need to touch the manifest, create XML files or use the shortcut manager. Just annotate the code that you want the shortcut to call.
The four shortcuts above are produced by the following code:
Shortcuts can be customized with attributes, just like using the framework API.
Kotlin
Java
Download
Shortbread is available on mavenCentral()
.
Kotlin
Java
Non-final resource IDs
If you are using resource IDs in @Shortcut
attributes auch as shortLabelRes
, which is recommended, you may see this
warning in Android Studio:
Resource IDs will be non-final in Android Gradle Plugin version 5.0, avoid using them as annotation attributes.
If the annotation is located inside a library, the project won't even compile. To overcome this, add the Shortbread
Gradle plugin and apply it to your modules:
Now make sure you use R2
instead of R
inside all @Shortcut
annotations. If you are using mipmap
as shortcut icon
resource type, switch to drawable
by simply moving the resources from the mipmap-
folders to the corresponding
drawable-
folders.
The plugin uses the [Butter Knife][2] Gradle plugin to generate the R2
class with final values. Referencing them does
not make the warning disappear (you can suppress it with @SuppressLint("NonConstantResourceId")
), but most likely will
be the only way to use resource IDs in annotations in the future.
Alternative to Gradle plugin
If for you can't (or don't want to) use the plugin, you can use the additional deprecated string attributes like
iconResName
, shortLabelResName
and so on.