Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Advertising ID in android programmatically

Tags:

android

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

like image 301
user3868543 Avatar asked Sep 15 '14 10:09

user3868543


People also ask

How do I find my Android advertising ID?

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.

How do I get Adid?

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 mobile Ad ID?

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.


1 Answers

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(); 
like image 128
DaniZ Avatar answered Oct 16 '22 03:10

DaniZ