Android 10:IMEI 在 API 29 上不再可用.寻找替代品 [英] Android 10: IMEI no longer available on API 29. Looking for alternatives

查看:175
本文介绍了Android 10:IMEI 在 API 29 上不再可用.寻找替代品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们客户的应用主要功能主要是跟踪客户的设备,他们提供绑定到特定手机(而不是其所有者)的产品.使用设备 imei 可以做到这一点,但随着 Android 10 中的隐私更改,他们无法访问.(https://developer.android.com/about/versions/10/privacy/变化).

Our client's app main feature is heavily relaying on tracking their clients' devices, they offer products that are bound to the specific phone(not its owner). This was possible using the device imei, but with the privacy changes in Android 10, they made it unreachable. (https://developer.android.com/about/versions/10/privacy/changes).

Android 有一个关于在特定用户案例中使用什么标识符的文档,但不符合我们的案例,因为我们需要它是唯一的、恒定的并绑定到设备(或至少难以更改).https://developer.android.com/training/articles/user-data-ids.我正在考虑将 Android ID 作为一种可能的解决方案,或者在知道它们不是 100% 可靠的情况下使用 mac 地址.

Android has a documentation about what identifier to use on specific user cases, but non matches our case since we need it to be unique, constant and bound to the device(or at least difficult to change). https://developer.android.com/training/articles/user-data-ids. I'm considering Android ID to be a possible solution, or using the mac address knowing they aren't 100% reliable.

有什么想法吗?建议?经验?在这一点上,任何事情都可以选择

Any thoughts? recommendations? experiences? at this point anything could be an option

推荐答案

我建议你阅读谷歌最佳实践的官方博客,看看哪个用例符合你的规范:https://developer.android.com/training/articles/user-data-ids.html

I advice you to read the official blog of the best practice of google to see what the use case match with your specification : https://developer.android.com/training/articles/user-data-ids.html

对我来说,我遇到了关于 android 标识符唯一性的同样问题,我发现唯一的解决方案是使用 MediaDrm API ( https://android.googlesource.com/platform/frameworks/base/+/android-cts-4.4_r1/media/java/android/media/MediaDrm.java#539 )它包含一个唯一的设备 ID,即使在恢复出厂设置时也能存活,并且不需要对清单文件的任何额外权限.

For me i occcured the same problem about the unicity of android identifiers and i found the only solution is to use the MediaDrm API ( https://android.googlesource.com/platform/frameworks/base/+/android-cts-4.4_r1/media/java/android/media/MediaDrm.java#539 ) which contains a unique device id and can survive even on the factory reset and doesn't need any additional permission on your manifest file.

这是我们如何在 Android 10 上检索唯一标识符的代码:

Here is the couple of code how can we retreive the unique identifier on Android 10 :

import android.media.MediaDrm
import java.security.MessageDigest
import java.util.*

object UniqueDeviceID {

    /**
     * UUID for the Widevine DRM scheme.
     * <p>
     * Widevine is supported on Android devices running Android 4.3 (API Level 18) and up.
     */
    fun getUniqueId(): String? {

        val WIDEVINE_UUID = UUID(-0x121074568629b532L, -0x5c37d8232ae2de13L)
        var wvDrm: MediaDrm? = null
        try {
            wvDrm = MediaDrm(WIDEVINE_UUID)
            val widevineId = wvDrm.getPropertyByteArray(MediaDrm.PROPERTY_DEVICE_UNIQUE_ID)
            val md = MessageDigest.getInstance("SHA-256")
            md.update(widevineId)
            return  md.digest().toHexString()
        } catch (e: Exception) {
            //WIDEVINE is not available
            return null
        } finally {
            if (AndroidPlatformUtils.isAndroidTargetPieAndHigher()) {
                wvDrm?.close()
            } else {
                wvDrm?.release()
            }
        }
    }


    fun ByteArray.toHexString() = joinToString("") { "%02x".format(it) }
}

这篇关于Android 10:IMEI 在 API 29 上不再可用.寻找替代品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆