Skip to content

Instantly share code, notes, and snippets.

@cybercoder-naj
Last active June 3, 2022 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cybercoder-naj/268fececded1c6aa77fedc0e50667b15 to your computer and use it in GitHub Desktop.
Save cybercoder-naj/268fececded1c6aa77fedc0e50667b15 to your computer and use it in GitHub Desktop.
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