Skip to content

Instantly share code, notes, and snippets.

@cybercoder-naj
Last active Jun 3, 2022
Embed
What would you like to do?
const val SHORTCUT_SECOND_ID = "id_second"
@RequiresApi(Build.VERSION_CODES.N_MR1)
fun createNewShortcut() {
val shortcutManager = getSystemService(context, ShortcutManager::class.java)
val secondActivity = ShortcutInfo.Builder(context, SHORTCUT_SECOND_ID)
.setShortLabel("Main")
.setIntents(arrayOf(
/* you should start with the Launcher Activity */
Intent(Intent.ACTION_VIEW, null, context, MainActivity::class.java),
Intent(Intent.ACTION_VIEW, null, context, SecondActivity::class.java)
))
.build()
shortcutManager!!.dynamicShortcuts = listOf(secondActivity)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment