Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
get device id for facebook ad test
public class customTask extends AsyncTask<Void, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected String doInBackground(Void... voids) {
AdvertisingIdClient.Info adInfo = null;
try {
adInfo = AdvertisingIdClient.getAdvertisingIdInfo(getApplicationContext());
} catch (IOException e) {
// ...
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
} catch (GooglePlayServicesRepairableException e) {
e.printStackTrace();
}
String userId = adInfo.getId();
return userId;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
Log.d("FACEBOOK_ID", "" + s.toString());
}
}
and it will execute like this
new customTask().execute();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.