From c134af889a47834321bfe8cd1341d782093b86e4 Mon Sep 17 00:00:00 2001 From: vrichv <1572349+vrichv@users.noreply.github.com> Date: Mon, 12 Aug 2024 17:50:30 +0800 Subject: [PATCH] Fix the issue that the app cannot be automatically launched on kitkat --- .../java/com/lizongying/mytv0/LocaleContextWrapper.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/lizongying/mytv0/LocaleContextWrapper.kt b/app/src/main/java/com/lizongying/mytv0/LocaleContextWrapper.kt index 7eb39f2e..a71b9820 100644 --- a/app/src/main/java/com/lizongying/mytv0/LocaleContextWrapper.kt +++ b/app/src/main/java/com/lizongying/mytv0/LocaleContextWrapper.kt @@ -6,9 +6,9 @@ import android.os.Build import android.os.LocaleList import java.util.Locale -class LocaleContextWrapper(base: Context) : ContextWrapper(base) { +class LocaleContextWrapper private constructor(base: Context) : ContextWrapper(base) { companion object { - fun wrap(context: Context, newLocale: Locale): ContextWrapper { + fun wrap(context: Context, newLocale: Locale): Context { val resources = context.resources val configuration = resources.configuration @@ -28,7 +28,12 @@ class LocaleContextWrapper(base: Context) : ContextWrapper(base) { context } - return LocaleContextWrapper(updatedContext) + // For KitKat and below, return the original context + return if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) { + updatedContext + } else { + LocaleContextWrapper(updatedContext) + } } } } \ No newline at end of file