【发布时间】:2015-08-28 14:46:07
【问题描述】:
我正在使用下面的代码在 android 中获取广告 id,但它给出了以下异常。
06-12 12:14:19.034: E/AndroidRuntime(13631): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.authorwjf.amianemulator/com.authorwjf.amianemulator.Main}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.google.android.gms.ads.identifier.AdvertisingIdClient$Info.getId()' on a null object reference
我在 android 清单文件中添加了 google play 服务库和元标记。
我在活动的 oncreate 方法中使用以下代码。
Info adInfo = null;
try {
adInfo = AdvertisingIdClient.getAdvertisingIdInfo(this);
} catch (IOException e) {
} catch (GooglePlayServicesNotAvailableException e) {
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (GooglePlayServicesRepairableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String AdId = adInfo.getId();
System.out.println("AdId :: "+AdId);
一些疑问::
genymotion 是否支持广告 id?
所有使用4.0及以上版本的安卓手机都有广告id吗?
请帮我获取广告ID。
【问题讨论】:
标签: android google-play google-play-services genymotion