[Android]Google 광고 ID 가져오기

Programming/Android 2018. 1. 25. 14:15 Posted by 생각하는로뎅
반응형

Google 광고 ID 를 가져오는 소스 코드입니다.


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 (Exception e) {

            e.printStackTrace();

        }

        String advertId = null;

        try{

            advertId = idInfo.getId();

        }catch (Exception e){

            e.printStackTrace();

        }

        return advertId;

    }

    @Override

    protected void onPostExecute(String advertId) {

        Dlog.d("idinfo : " + advertId);

    }


};

task.execute();




만약 프로가드를 적용하신다면, 아래와 같이 설정해줍니다.



-keep class * extends java.util.ListResourceBundle {

    protected Object[][] getContents();  }


 -keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {

    public static final *** NULL;      }


-keepnames @com.google.android.gms.common.annotation.KeepName class *

-keepclassmembernames class * {

     @com.google.android.gms.common.annotation.KeepName *;

}


-keepnames class * implements android.os.Parcelable {

    public static final ** CREATOR;

}




반응형