mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
fix: remove misleading stacktrace log when launching application (fixes #1392)
This commit is contained in:
@@ -68,7 +68,7 @@ class LaunchAppAction(context: Context, override val order: Int) : EditorActivit
|
||||
}
|
||||
|
||||
val activity = data.requireActivity()
|
||||
IntentUtils.launchApp(activity, packageName)
|
||||
IntentUtils.launchApp(activity, packageName, logError = false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import com.itsaky.androidide.utils.flashError
|
||||
/**
|
||||
* @see openApplicationModuleChooser
|
||||
*/
|
||||
fun openApplicationModuleChooser(data: ActionData, callback: (AndroidModule) -> Unit) =
|
||||
inline fun openApplicationModuleChooser(data: ActionData, crossinline callback: (AndroidModule) -> Unit) =
|
||||
openApplicationModuleChooser(data.requireContext(), callback)
|
||||
|
||||
/**
|
||||
@@ -38,7 +38,7 @@ fun openApplicationModuleChooser(data: ActionData, callback: (AndroidModule) ->
|
||||
*
|
||||
* @param
|
||||
*/
|
||||
fun openApplicationModuleChooser(context: Context, callback: (AndroidModule) -> Unit) {
|
||||
inline fun openApplicationModuleChooser(context: Context, crossinline callback: (AndroidModule) -> Unit) {
|
||||
val log = ILogger.newInstance("ActionUtils")
|
||||
val projectManager = IProjectManager.getInstance()
|
||||
val applications = projectManager.getAndroidAppModules()
|
||||
|
||||
@@ -95,32 +95,37 @@ object IntentUtils {
|
||||
* @param context The context that will be used to fetch the launch intent.
|
||||
* @param packageName The package name of the application.
|
||||
*/
|
||||
fun launchApp(context: Context, packageName: String) {
|
||||
@JvmOverloads
|
||||
fun launchApp(context: Context, packageName: String, logError: Boolean = true) : Boolean {
|
||||
if (Build.VERSION.SDK_INT >= 33) {
|
||||
launchAppApi33(context, packageName)
|
||||
return
|
||||
return launchAppApi33(context, packageName, logError)
|
||||
}
|
||||
|
||||
doLaunchApp(context, packageName)
|
||||
return doLaunchApp(context, packageName, logError)
|
||||
}
|
||||
|
||||
private fun doLaunchApp(context: Context, packageName: String) {
|
||||
private fun doLaunchApp(context: Context, packageName: String, logError: Boolean = true) : Boolean {
|
||||
try {
|
||||
val launchIntent = context.packageManager.getLaunchIntentForPackage(packageName)
|
||||
requireNotNull(launchIntent) {
|
||||
"Cannot get launch intent for package '$packageName'. Is the application installed?"
|
||||
if (launchIntent == null) {
|
||||
flashError(R.string.msg_app_launch_failed)
|
||||
return false
|
||||
}
|
||||
|
||||
context.startActivity(launchIntent)
|
||||
return true
|
||||
} catch (e: Throwable) {
|
||||
flashError(R.string.msg_app_launch_failed)
|
||||
ILogger.instance().error("Failed to launch application with package name '$packageName'", e)
|
||||
if (logError) {
|
||||
ILogger.instance().error("Failed to launch application with package name '$packageName'", e)
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(33)
|
||||
private fun launchAppApi33(context: Context, packageName: String) {
|
||||
try {
|
||||
private fun launchAppApi33(context: Context, packageName: String, logError: Boolean = true) : Boolean {
|
||||
return try {
|
||||
val sender = context.packageManager.getLaunchIntentSenderForPackage(packageName)
|
||||
sender.sendIntent(
|
||||
context,
|
||||
@@ -129,9 +134,13 @@ object IntentUtils {
|
||||
null,
|
||||
null
|
||||
)
|
||||
true
|
||||
} catch (e: Throwable) {
|
||||
flashError(R.string.msg_app_launch_failed)
|
||||
ILogger.instance().error("Failed to launch application with package name '$packageName'", e)
|
||||
if (logError) {
|
||||
ILogger.instance().error("Failed to launch app", e)
|
||||
}
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -534,7 +534,7 @@
|
||||
<string name="idepref_general_themeSelector_title">Theme</string>
|
||||
<string name="idepref_general_themeSelector_summary">Select a theme for AndroidIDE (requires restart).</string>
|
||||
<string name="idepref_general_projectConfig">Project configuration</string>
|
||||
<string name="msg_app_launch_failed">Failed to launch application. See IDE logs for more info.</string>
|
||||
<string name="msg_app_launch_failed">Launch failed. Install the application first.</string>
|
||||
<string name="idepref_java_diagnosticEnabled_title">Diagnostics enabled</string>
|
||||
<string name="idepref_java_diagnosticsEnabled_summary">(EXPERIMENTAL) Whether the Java source files should be analyzed for errors or not.</string>
|
||||
<string name="title_reload_color_schemes">Reload color schemes</string>
|
||||
|
||||
Reference in New Issue
Block a user