【问题标题】:not able to get advertising id in android无法在android中获取广告ID
【发布时间】: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);

一些疑问::

  1. genymotion 是否支持广告 id?

  2. 所有使用4.0及以上版本的安卓手机都有广告id吗?

请帮我获取广告ID。

【问题讨论】:

    标签: android google-play google-play-services genymotion


    【解决方案1】:

    您收到此异常是因为设备(或模拟器)上未安装 Google Play 服务。

    您可以在 Google Play 服务文档中阅读:

    注意:由于很难预测每个设备的状态,您 在您之前必须始终检查兼容的 Google Play 服务 APK 访问 Google Play 服务功能。

    参考:https://developers.google.com/android/guides/setup#ensure_devices_have_the_google_play_services_apk

    您可以使用isGooglePlayServicesAvailable方法检查是否安装了Google Play服务,例如:

    if(GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this) == ConnectionResult.SUCCESS) {
        //Google Play Services are available
    } else {
        //Google Play Services are not available, or not updated
    }
    

    genymotion 支持广告id吗?

    可以,但您需要手动安装 Google Play 服务。看到这个answer

    在所有正在使用的 android 手机中都提供广告 ID 4.0及以上?

    不,Google Play 服务可能不可用。

    【讨论】:

    • 谢谢Mattia...很好的解释它解决了我的问题...实际上我正在寻找可以阻止我的应用程序在模拟器上运行的东西...我已经尝试过构建no,制造商等阻止模拟器....但仍然有一些黑客将其安装在某些模拟器/模拟器上或绕过 vpn 或运行一些自动脚本......我不知道他们在做什么......
    • 实际上我的应用程序就像一个优惠墙,用户可以安装和运行应用程序并在获得积分后获得积分,他们可以提取资金......有些用户滥用它而我的客户不是获得广告系列的安装,即使安装了广告系列并且赔钱....看看你是否可以在这里帮助我......
    • 我已经为此发布了一个问题,但没有得到任何正确的回应......希望你能在这里帮助我......stackoverflow.com/questions/30800289/…
    猜你喜欢
    • 2020-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-04
    • 2014-11-08
    相关资源
    最近更新 更多