Android 获取手机设备基础信息

104 阅读1分钟
import android.content.Context
import android.os.Build
import android.provider.Settings
import java.util.*

/**
 * 手机工具类
 */
object MobileDevicesInfoUtils {

    // 获取手机制造厂商
    fun getManufacturer(): String {
        return Build.MANUFACTURER
    }

    // 获取手机型号
    fun getModel(): String {
        return Build.MODEL
    }

    // 获取手机系统当前使用的语言
    fun getCurrentLanguage(): String {
        return Locale.getDefault().language
    }

    // 获取Android系统版本号
    fun getSystemVersion(): String {
        return Build.VERSION.RELEASE
    }

    // 获取手机中的语言列表
    fun getLanguageList(context: Context): List<Locale> {
        val localeList = mutableListOf<Locale>()
        val locales = context.resources.configuration.locales
        for (i in 0 until locales.size()) {
            localeList.add(locales[i])
        }
        return localeList
    }

    //获取手机设备id
    fun getPhoneDeviceId(context: Context): String {
        val contentResolver = context.contentResolver
        return Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID)
    }
}