Android: Get Installed Shortcuts

前端 未结 4 1616
名媛妹妹
名媛妹妹 2021-01-17 22:27

I have seen ways to make shortcuts, but I need to find a way to get a list of shortcuts installed on the phone.

I want my user to be able to select one of his/her sh

4条回答
  •  孤独总比滥情好
    2021-01-17 23:02

    In addition to Jonathan,

    Each app can do shortcuts. Each shortcut specified in app's manifest. So you can get shortcuts list (this method in activity):
    Kotlin

    fun printShortcuts() {
        val shortcutIntent = Intent(Intent.ACTION_CREATE_SHORTCUT)
        val shortcuts = packageManager.queryIntentActivities(shortcutIntent, 0)
        shortcuts.forEach {
            println("name = ${it.activityInfo.name}, label = ${it.loadLabel(packageManager)}")
        }
    }
    

    It will print something like:

    I/System.out: name = com.whatsapp.camera.CameraActivity, label = WhatsApp Camera
    I/System.out: name = com.android.contacts.ContactShortcut, label = Contact
    I/System.out: name = alias.DialShortcut, label = Direct dial
    I/System.out: name = alias.MessageShortcut, label = Direct message
    

提交回复
热议问题