本文介绍了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用作可能的解决方案,或者使用mac地址知道它们并非100%可靠.

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

推荐答案

我建议您阅读google最佳实践的官方博客,以了解用例与您的规范相匹配的内容: 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上不再可用.寻找替代方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 04:54
查看更多