packagejp.gr.java_conf.fofn.advertisingid;importandroid.app.Activity;importandroid.content.Context;importandroid.os.AsyncTask;importandroid.support.v7.app.AppCompatActivity;importandroid.os.Bundle;importandroid.util.Log;importandroid.widget.TextView;importcom.google.android.gms.ads.identifier.AdvertisingIdClient;importcom.google.android.gms.common.GooglePlayServicesNotAvailableException;importcom.google.android.gms.common.GooglePlayServicesRepairableException;importjava.io.IOException;publicclassMainActivityextendsAppCompatActivity{privatestaticfinalStringTAG="AdvertisingId";classAdIdTaskextendsAsyncTask<Void,Void,String>{privateActivitymActivity;AdIdTask(Activityactivity){mActivity=activity;}@OverrideprotectedStringdoInBackground(Void...params){StringadvertisingId="";try{AdvertisingIdClient.Infoinfo=AdvertisingIdClient.getAdvertisingIdInfo(mActivity.getApplicationContext());advertisingId=info.getId();}catch(GooglePlayServicesNotAvailableExceptione){Log.e(TAG,"GooglePlayServices not available.");}catch(GooglePlayServicesRepairableExceptione){//}catch(IOExceptione){//}returnadvertisingId;}@OverrideprotectedvoidonPostExecute(Stringid){TextViewview=(TextView)mActivity.findViewById(R.id.adid);view.append(id);}}@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);// AdvertisingIdClient cannot be called in the main thread.AsyncTask<Void,Void,String>task=newAdIdTask(this);task.execute();}}