Created
February 13, 2019 14:44
-
-
Save f0ster/caef313bb3aa9a1a67e8449a05493f94 to your computer and use it in GitHub Desktop.
get android ad id
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment