簡體   English   中英

獲取設備 ID - Express

[英]Get device ID - Express

我正在構建移動應用程序。

堆:

服務器:快遞

客戶: Android

我需要提取設備的唯一 ID 或唯一但在服務器端的東西,因此不要在客戶端的請求正文中提供 - 可能是一些唯一的標頭或像這樣的 smt

非常感謝!

fun getDeviceId(): String {
    return try {
        val deviceId =
            "35" + Build.BOARD.length % 10 + Build.BRAND.length % 10 + Build.CPU_ABI.length % 10 + Build.DEVICE.length % 10 + Build.MANUFACTURER.length % 10 + Build.MODEL.length % 10 + Build.PRODUCT.length % 10
        var serial: String? = null
        try {
            serial = Build::class.java.getField("SERIAL")[null].toString()
            return UUID(deviceId.hashCode().toLong(), serial.hashCode().toLong()).toString()
        } catch (exception: Exception) {
            serial = "serial" // some value
        }
        val id = UUID(deviceId.hashCode().toLong(), serial.hashCode().toLong()).toString()
        if (id.length > 40) id.substring(0, 40) else id
    } catch (e: Exception) {
        e.printStackTrace()
        ""
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM