Skip to content

Instantly share code, notes, and snippets.

@pavelsust
Created August 15, 2019 10:11
Show Gist options
  • Save pavelsust/299667b5f271958b8575bc600c5faf39 to your computer and use it in GitHub Desktop.
Save pavelsust/299667b5f271958b8575bc600c5faf39 to your computer and use it in GitHub Desktop.
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