gpt4 book ai didi

android - 广告 SDK 似乎无法从设备获取广告信息

转载 作者:行者123 更新时间:2023-11-29 00:15:26 25 4
gpt4 key购买 nike

这是我们从 Mopub 和其他广告网络看到的:

java.io.IOException: Connection failure com.google.android.gms.ads.identifier.AdvertisingIdClient.g(Unknown Source) com.google.android.gms.ads.identifier.AdvertisingIdClient.getAdvertisingIdInfo(Unknown Source)

他们似乎都有同样的问题。

奇怪的是,我们可以毫无问题地使用以下来源从我们的应用程序获取广告 ID。我们获得了正确的广告 ID,并且没有错误日志。所有 SDK 都遇到相同的问题(连接失败)。

感谢任何帮助。

private void getAdvertisingId(AdvertisingIdHolder receiver) {

AdvertisingIdClient.Info adInfo = null;
String id = null;
boolean isLAT = false;

try {
adInfo = AdvertisingIdClient.getAdvertisingIdInfo(App.getCtx());

id = adInfo.getId();
isLAT = adInfo.isLimitAdTrackingEnabled();
} catch (IOException e) {
SLog.e("error", e);
// Unrecoverable error connecting to Google Play services (e.g.,
// the old version of the service doesn't support getting AdvertisingId).
} catch (GooglePlayServicesNotAvailableException e) {
SLog.e("error", e);
// Google Play services is not available entirely.
} catch (GooglePlayServicesRepairableException e) {
e.printStackTrace();
}

receiver.receive(id, isLAT);
}

最佳答案

这几天我在获取广告 ID 上经历了反复试验。最后我得到了它!如果我们传入 getApplicationContext() 而不是当前 Activity 的上下文,则可以解决连接错误。以下是我的工作代码:

private void getGaid() {
new Thread(new Runnable() {

@Override
public void run() {
try {
String gaid = AdvertisingIdClient.getAdvertisingIdInfo(
getApplicationContext()).getId();
if (gaid != null) {
Log.d("DEBUG", gaid);
// gaid get!
}
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (GooglePlayServicesRepairableException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
}
}).start();
}

getGaid() 可以放在 View 的 onCreate()、onResume() 或 onClick() 中,只要线程被主 ui 线程调用即可。

您可能需要做的另一件事是将 google play 服务库更新到最新版本。如官方文档here提到,IOException可能是因为旧版本的服务不支持获取AdvertisingId导致的。

如有任何其他问题,请随时发表评论。

关于android - 广告 SDK 似乎无法从设备获取广告信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27257877/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com