The Code A can create a Pin Shortcut of desktop, the following content is document of requestPinShortcut
.
Note the API will return without waiting for the user to respond, so getting TRUE from this API does not mean the shortcut was pinned successfully. FALSE if the launcher doesn't support this feature.
I hope to do something when a user has created the Pin Shortcut, I think a callback function can do that, how can I create a callback function for requestPinShortcut
?
Code A
fun requestPin(context: Context) {
val shortcutManager = context.getSystemService(ShortcutManager::class.java)
val shortcutList = shortcutManager.pinnedShortcuts
if (shortcutList.isEmpty()) {
if (shortcutManager.isRequestPinShortcutSupported) {
val pinShortcutInfo = ShortcutInfo.Builder(context, SHORTCUT_ID).build()
shortcutManager.requestPinShortcut(pinShortcutInfo, null)
}
}
}