【问题标题】:Google advertising ID Returning Null on NougatGoogle 广告 ID 在 Nougat 上返回 Null
【发布时间】:2017-09-12 18:14:59
【问题描述】:

我在我的应用程序中使用了广告 ID,并且代码运行良好,我在运行 Android Nougat 7.1.2 的设备上对其进行了测试。你能指出我应该添加什么才能在牛轧糖中得到它吗?

private static void getAdvertisingID() {
    AsyncTask<Void, Void, String> task = new AsyncTask<Void, Void, String>() {
        @Override
        protected String doInBackground(Void... params) {
            AdvertisingIdClient.Info idInfo = null;
            try {
                idInfo = AdvertisingIdClient.getAdvertisingIdInfo(_context);
                if (idInfo.isLimitAdTrackingEnabled()){ // check if user has opted out of tracking
                    Log.i("NetworkStateChangeReceiver","Not Found");
                    return "did not found GAID... sorry";
                }
            } catch (GooglePlayServicesNotAvailableException e) {
                e.printStackTrace();
            } catch (GooglePlayServicesRepairableException e) {
                e.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }
            String advertId = null;
            try{
                advertId = idInfo.getId();
            }catch (Exception e){
                e.printStackTrace();
            }
            return advertId;
        }
        @Override
        protected void onPostExecute(String advertId) {
            Log.i("NetworkStateChangeReceiver","Found "+advertId);
            UtilHelper.setDeviceIDFA(advertId);
        }
    };
    task.execute();
}

【问题讨论】:

    标签: android android-7.1-nougat google-advertising-id


    【解决方案1】:

    结果代码工作正常,唯一的问题是在 Nougat 上调用 onPostExecute 方法需要一些时间,而在其他运行较低 android 版本的设备上,此方法调用速度很快。我只是在调用getAdvertisingID 后添加了一些延迟来获取广告 ID,一切正常。 快乐编码

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-01
      • 1970-01-01
      • 2018-04-11
      • 2019-04-24
      • 2020-08-01
      相关资源
      最近更新 更多