美文网首页
获取android设备唯一识别码

获取android设备唯一识别码

作者: Sunny君907 | 来源:发表于2019-01-15 16:44 被阅读0次

在个别机型下面,通过telephonyManager获取deviceId为空,可通过Setting.Secure方式获取android设备唯一识别码

@Suppress("DEPRECATION")
@SuppressLint("HardwareIds")
fun getDeviceId(context: Context?) : String?{
    var deviceId: String? = null
    try {
        deviceId = (context?.applicationContext?.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager).deviceId
        if (deviceId == null) {
            deviceId = Settings.Secure.getString(context.applicationContext.contentResolver, Settings.Secure.ANDROID_ID)
        }
    } catch (e: Exception){

    } finally {
        return deviceId
    }
}

参考链接:https://stackoverflow.com/questions/3802644/will-telephonymanger-getdeviceid-return-device-id-for-tablets-like-galaxy-tab

相关文章

网友评论

      本文标题:获取android设备唯一识别码

      本文链接:https://www.haomeiwen.com/subject/vpvydqtx.html