make sure casual static shortcuts work too

This commit is contained in:
tibbi 2022-10-09 20:12:59 +02:00
parent fd9c7b3787
commit 417deef01c
2 changed files with 12 additions and 6 deletions

View File

@ -391,12 +391,17 @@ class MainActivity : SimpleActivity(), FlingListener {
if (clickedGridItem.type == ITEM_TYPE_ICON) {
launchApp(clickedGridItem.packageName)
} else if (clickedGridItem.type == ITEM_TYPE_SHORTCUT) {
val id = clickedGridItem.shortcutId
val packageName = clickedGridItem.packageName
val userHandle = android.os.Process.myUserHandle()
val shortcutBounds = home_screen_grid.getClickableRect(clickedGridItem)
val launcherApps = applicationContext.getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps
launcherApps.startShortcut(packageName, id, shortcutBounds, null, userHandle)
if (clickedGridItem.intent.isNotEmpty()) {
launchShortcutIntent(clickedGridItem)
} else {
// launch pinned shortcuts
val id = clickedGridItem.shortcutId
val packageName = clickedGridItem.packageName
val userHandle = android.os.Process.myUserHandle()
val shortcutBounds = home_screen_grid.getClickableRect(clickedGridItem)
val launcherApps = applicationContext.getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps
launcherApps.startShortcut(packageName, id, shortcutBounds, null, userHandle)
}
}
}
}

View File

@ -38,6 +38,7 @@ fun Activity.uninstallApp(packageName: String) {
}
}
// launch static or dynamic shortcuts that have intents as string
fun Activity.launchShortcutIntent(item: HomeScreenGridItem) {
try {
val intent = Intent.parseUri(item.intent, 0)