【问题标题】:How to get Advertising id in android?如何在android中获取广告ID?
【发布时间】:2016-07-20 17:50:06
【问题描述】:

当我从活动和片段中调用时,我使用了这段代码

import com.google.android.gms.ads.identifier.AdvertisingIdClient.Info;


Info adInfo = null;

try {
     adInfo = AdvertisingIdClient.getAdvertisingIdInfo(mContext);
} catch (IOException e) {
     e.printStackTrace();
} catch (GooglePlayServicesAvailabilityException e) {
     e.printStackTrace();
} catch (GooglePlayServicesNotAvailableException e) {
     e.printStackTrace();
}

String AdId = adInfo.getId();

但是当我从像 Package Removed 这样的待处理意图调用时,我想调用网络服务,我需要广告 id,但我得到了 null。如果你们以前做过,请建议我。提前谢谢。

【问题讨论】:

  • 在您的应用中使用 AAID 的目的是什么?你想在设备重启时获取设备唯一 ID 甚至不会改变吗?

标签: android


【解决方案1】:

尝试使用应用上下文

因为接收者可以使用活动上下文或应用上下文 - 取决于谁以及如何启动接收者

 AdvertisingIdClient.getAdvertisingIdInfo(context.getApplicationContext());

【讨论】:

  • 我有一个疑问,请帮助我,如何获取用户的唯一ID,即使从设备中清除数据也无法更改,我听说过“广告ID”,是它解决了我的问题,请帮助我。谢谢
【解决方案2】:

你可以试试这段代码并在 onCreate 上调用下面的方法

public void getAAID()
{
    AsyncTask.execute(new Runnable() {
        @Override
        public void run() {
            try {
                AdvertisingIdClient.Info adInfo = AdvertisingIdClient.getAdvertisingIdInfo(MyActivity.this);
                String myId = adInfo != null ? adInfo.getId() : null;

               Log.i("UIDMY",myId);
            } catch (Exception e) {
                 Log.e("error", e);
            }
        }
    });
}

查看完整帖子:how to get AAID programmatically

【讨论】:

  • AAID 是 unquie 设备 ID,是否在设备重启或重置或数据清除时发生变化?
猜你喜欢
  • 2015-08-28
  • 2020-06-12
  • 2014-11-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-06-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多