feat: 修改获取设备名称

This commit is contained in:
PeanutMelonSeedBigAlmond
2024-02-02 20:16:50 +08:00
parent afe7bdb4b5
commit 0072f28ec5

View File

@@ -3,6 +3,7 @@ package com.lifegpc.ehf
import android.app.Activity
import android.content.Intent
import android.os.Build
import android.provider.Settings
import android.view.WindowManager
import com.lifegpc.ehf.annotation.ChannelMethod
import com.lifegpc.ehf.eventbus.SAFAuthEvent
@@ -68,5 +69,11 @@ class MainActivity : FlutterActivity() {
@ChannelMethod(methodName = "deviceName")
@Suppress("unused")
private fun getDeviceName(): String = Build.MODEL
private fun getDeviceName(): String {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
Settings.Global.getString(contentResolver, Settings.Global.DEVICE_NAME) ?: Build.MODEL
} else {
Build.MODEL
}
}
}