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;
}
'Programming > Android' 카테고리의 다른 글
Android 전화 상태 리시버(Receiver) (0) | 2018.04.05 |
---|---|
Android 8.0(O) TYPE_SYSTEM_ALERT (0) | 2018.04.05 |
[에러]AAPT2 error: check logs for details (0) | 2017.11.21 |
Android 8.0(Oreo) 알림(Notification) 사용법 (0) | 2017.10.01 |
Wifi 수신 레벨 5단계로 나누기 (0) | 2017.08.08 |