适配安卓10获取唯一标识

    Android 10(API 级别 29)引入了多项功能和行为变更,目的是更好
    地保护用户的隐私权。这些变更能让用户更清楚地了解并更好地控制
    他们的数据及为应用提供的权能。这些隐私权功能可能意味着应用所
    依赖的特定行为或数据可能会与较低版本的平台有所不同。

一,使用移动智能终端补充设备标识体系统一调用 SDK
说明:提供稳定唯一标识:OAID
1.SDK 下载地址: http://www.msa-alliance.cn/
2.覆盖机型范围:
适配安卓10获取唯一标识_第1张图片
3.开发者文档:
http://thoughts.hztianque.com/workspaces/5cbfc067be825b4f93d0fb70/files/5e563e5f883c930001bdb65a
4.代码片段:
初始化:Application
Application
TQRouter.getAppLCOCaller()
.addLCObserver(new DeviceinitLCO())
.callOnCreate(this);
public class DeviceinitLCO extends AppLCObserver {

private static String oaid;
private static boolean isSupportOaid=true;
private static int errorCode;



@Override
public void onCreate(Application application) {
    //获取OAID等设备标识符
    MiitHelper miitHelper = new MiitHelper(appIdsUpdater);
    miitHelper.getDeviceIds(application);
}

private MiitHelper.AppIdsUpdater appIdsUpdater = new MiitHelper.AppIdsUpdater() {
    @Override
    public void OnIdsAvalid(@NonNull String ids) {
        Log.e("++++++ids: ", ids);
        oaid = ids;
    }
};

public static String getOaid() {
    return oaid;
}
public static String getErrorCode() {
    return String.valueOf(errorCode);
}

public static boolean isSupportOaid() {
    return isSupportOaid;
}

public static void setIsSupportOaid(boolean isSupportOaid) {
    DeviceinitLCO.isSupportOaid = isSupportOaid;
}
public static void setIsSupportOaid(boolean isSupportOaid,int ErrorCode) {
    DeviceinitLCO.isSupportOaid = isSupportOaid;
    DeviceinitLCO.errorCode=ErrorCode;
}


@Override
public void onStop() {

}

}

   获取OAID:

public static String getOaid() {
String idfa;
if (DeviceinitLCO.isSupportOaid()) {
idfa = DeviceinitLCO.getOaid();
} else {
idfa = "获取失败,ErrorCode: " + DeviceinitLCO.getErrorCode();
}

你可能感兴趣的:(安卓10获取唯一标识)