mirror of
https://github.com/jrpie/Launcher.git
synced 2025-07-17 21:04:47 +02:00
handle SecurityException when trying to launch an app
Some checks failed
Android CI / build (push) Has been cancelled
Some checks failed
Android CI / build (push) Has been cancelled
This commit is contained in:
parent
eef0e57f4b
commit
4af6f96d2c
2 changed files with 9 additions and 1 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue