handle SecurityException when trying to launch an app
Some checks failed
Android CI / build (push) Has been cancelled

This commit is contained in:
Josia Pietsch 2025-07-16 01:08:49 +02:00
parent eef0e57f4b
commit 4af6f96d2c
Signed by: jrpie
GPG key ID: E70B571D66986A2D
2 changed files with 9 additions and 1 deletions

View file

@ -9,6 +9,7 @@ import android.content.pm.LauncherApps
import android.graphics.Rect
import android.graphics.drawable.Drawable
import android.util.Log
import android.widget.Toast
import de.jrpie.android.launcher.R
import de.jrpie.android.launcher.apps.AppInfo
import de.jrpie.android.launcher.apps.AbstractAppInfo.Companion.INVALID_USER
@ -28,7 +29,13 @@ class AppAction(val app: AppInfo) : Action {
context.getSystemService(Service.LAUNCHER_APPS_SERVICE) as LauncherApps
app.getLauncherActivityInfo(context)?.let { app ->
Log.i("Launcher", "Starting ${this.app}")
launcherApps.startMainActivity(app.componentName, app.user, rect, null)
try {
launcherApps.startMainActivity(app.componentName, app.user, rect, null)
} catch (e: SecurityException) {
Log.i("Launcher", "Unable to start ${this.app}: ${e.message}")
Toast.makeText(context, context.getString(R.string.toast_cant_launch_app), Toast.LENGTH_LONG).show()
return false
}
return true
}
}

View file

@ -456,4 +456,5 @@
<string name="content_description_navigate_next">Navigate next</string>
<string name="content_description_lock">Lock</string>
<string name="content_description_settings_actions_row_button_remove">Remove binding</string>
<string name="toast_cant_launch_app">Error: Can\'t launch app</string>
</resources>