Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lib_base
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sikang
lib_base
Commits
b1de2a04
Commit
b1de2a04
authored
Jan 02, 2019
by
sikang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Headers添加 GA_ID
parent
7725a4bb
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
1 deletions
+28
-1
src/main/java/tech/starwin/network/DefaultHeaderAddInterceptor.java
+28
-1
No files found.
src/main/java/tech/starwin/network/DefaultHeaderAddInterceptor.java
View file @
b1de2a04
...
@@ -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
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment