I use the code below to get the ad id in android, but this gives the following exception.
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
I added the google play services library and meta tag in the Android manifest file.
I use the below code in the oncreate activity method.
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);
Some doubts ::
Please help me get the ad id.
source share