I want to get users Advertising ID programmatically.I used the below code from the developer site.But its not working
Info adInfo = null; try { adInfo = AdvertisingIdClient.getAdvertisingIdInfo(getApplicationContext()); } catch (IOException e) { // Unrecoverable error connecting to Google Play services (e.g., // the old version of the service doesn't support getting AdvertisingId). } catch (GooglePlayServicesNotAvailableException e) { // Google Play services is not available entirely. } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (GooglePlayServicesRepairableException e) { // TODO Auto-generated catch block e.printStackTrace(); } final String id = adInfo.getId(); final boolean isLAT = adInfo.isLimitAdTrackingEnabled();
How can I get user's advertising id programmatically ?? please help me
Android – Find your Advertising ID Simply open the Google Settings app on your Android device and click on “Ads.” Your Advertising Identifier will be listed at the bottom of the screen.
To find your device's advertising ID: Android devices – To find your Google advertising ID (GAID), open the Settings app on your Android device, click on Google, and then select “Ads” under Services. Your GAID will be listed at the bottom of the screen.
What is a mobile advertising ID? A mobile advertising ID (or MAID for short) is a unique, anonymous alphanumeric identifier that iOS or Android assigns to each mobile device. MAIDs were built for the advertising community. Like cookies, mobile advertising IDs connect activity back to a real person.
I might be late but this might help someone else!
AsyncTask<Void, Void, String> task = new AsyncTask<Void, Void, String>() { @Override protected String doInBackground(Void... params) { AdvertisingIdClient.Info idInfo = null; try { idInfo = AdvertisingIdClient.getAdvertisingIdInfo(getApplicationContext()); } catch (GooglePlayServicesNotAvailableException e) { e.printStackTrace(); } catch (GooglePlayServicesRepairableException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } String advertId = null; try{ advertId = idInfo.getId(); }catch (NullPointerException e){ e.printStackTrace(); } return advertId; } @Override protected void onPostExecute(String advertId) { Toast.makeText(getApplicationContext(), advertId, Toast.LENGTH_SHORT).show(); } }; task.execute();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With