Commit b1de2a04 by sikang

Headers添加 GA_ID

parent 7725a4bb
...@@ -3,6 +3,10 @@ package tech.starwin.network; ...@@ -3,6 +3,10 @@ package tech.starwin.network;
import android.text.TextUtils; import android.text.TextUtils;
import com.google.android.gms.ads.identifier.AdvertisingIdClient;
import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
import com.google.android.gms.common.GooglePlayServicesRepairableException;
import java.io.IOException; import java.io.IOException;
import okhttp3.Interceptor; import okhttp3.Interceptor;
...@@ -19,6 +23,8 @@ import tech.starwin.R; ...@@ -19,6 +23,8 @@ import tech.starwin.R;
*/ */
class DefaultHeaderAddInterceptor implements Interceptor { class DefaultHeaderAddInterceptor implements Interceptor {
public static String GA_ID = "";
@Override @Override
public Response intercept(Chain chain) throws IOException { public Response intercept(Chain chain) throws IOException {
Request userRequest = chain.request(); Request userRequest = chain.request();
...@@ -63,9 +69,30 @@ class DefaultHeaderAddInterceptor implements Interceptor { ...@@ -63,9 +69,30 @@ class DefaultHeaderAddInterceptor implements Interceptor {
.header("X-APP-VERSION-NAME", String.valueOf(LibConfig.VERSION_NAME)) .header("X-APP-VERSION-NAME", String.valueOf(LibConfig.VERSION_NAME))
.header("X-APP-PACKAGE-NAME", LibConfig.APPLICATION_ID) .header("X-APP-PACKAGE-NAME", LibConfig.APPLICATION_ID)
.header("X-APP-NAME", LibConfig.APP_NAME) .header("X-APP-NAME", LibConfig.APP_NAME)
.header("X-AF-ID", LibConfig.APPSFLYER_DEV_KEY); .header("X-AF-ID", LibConfig.APPSFLYER_DEV_KEY)
.header("X-GA-ID", getGAId());
return chain.proceed(requestBuilder.build()); return chain.proceed(requestBuilder.build());
} }
private String getGAId() {
if (!TextUtils.isEmpty(GA_ID)) {
return GA_ID;
}
AdvertisingIdClient.Info adInfo = null;
try {
adInfo = AdvertisingIdClient.getAdvertisingIdInfo(LibConfig.getContext());
GA_ID = adInfo.getId();
} catch (IOException e) {
// Unrecoverable error connecting to Google Play services (e.g.,
// the old version of the service doesn't support getting AdvertisingId).
} catch (GooglePlayServicesNotAvailableException e) {
// Google Play services is not available entirely.
} catch (GooglePlayServicesRepairableException e) {
e.printStackTrace();
}
return GA_ID;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment