From 1d9621129f095e20badd36a33a183b4e84bc0d3d Mon Sep 17 00:00:00 2001 From: heyawei <379135467@qq.com> Date: Wed, 19 May 2021 16:07:00 +0800 Subject: [PATCH] =?UTF-8?q?StringRequest.postJson=20=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=EF=BC=88=E8=8E=B7=E5=8F=96=E8=AF=AD=E8=A8=80=E5=9C=B0=E5=8C=BA?= =?UTF-8?q?=E7=A0=81=E9=97=AE=E9=A2=98=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://console.firebase.google.com/project/tencent-iot/crashlytics/app/android:com.tencent.iot.explorer.link.opensource/issues/f4ea89f408582e2b05f88b541427d390?time=last-ninety-days&sessionEventKey=605AB989033B00012DDD273F4B2CA680_1521510826317939172 Change-Id: Iaff83d0606cdc4b477d5de557acd2bf7f495d843 --- .../iot/explorer/link/core/utils/Utils.kt | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/sdk/explorer-link-android/src/main/java/com/tencent/iot/explorer/link/core/utils/Utils.kt b/sdk/explorer-link-android/src/main/java/com/tencent/iot/explorer/link/core/utils/Utils.kt index 9eb73ef53..b5362a735 100644 --- a/sdk/explorer-link-android/src/main/java/com/tencent/iot/explorer/link/core/utils/Utils.kt +++ b/sdk/explorer-link-android/src/main/java/com/tencent/iot/explorer/link/core/utils/Utils.kt @@ -8,8 +8,10 @@ import android.graphics.Bitmap import android.graphics.BitmapFactory import android.graphics.Canvas import android.os.Build +import android.os.LocaleList import android.provider.Settings import android.text.TextUtils +import android.util.Log import com.tencent.iot.explorer.link.core.log.L import java.io.ByteArrayOutputStream import java.io.IOException @@ -59,18 +61,20 @@ object Utils { } fun getLang(): String { - val local = Locale.getDefault().toString() - if (TextUtils.isEmpty(local)) { + var local: Locale? + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + local = LocaleList.getDefault().get(0) + } else { + local = Locale.getDefault() + } + + if (local == null) { L.d("getLang return default lang(zh-CN)") return "zh-CN" // 默认时返回中文类型 } - var tmp = local - val eleArray = tmp.split("_") - if (eleArray.size >= 3) { - tmp = eleArray[0] + "_" + eleArray[1] - } - val ret = tmp.replace("_", "-") - L.d("getLang return $ret") + + var ret = local.getLanguage().toString() + "-" + local.getCountry().toString() return ret }