Commit 079c5d473a18b132b52fac1385b5f4a28d14ec43
1 parent
3c7e91f31a
Exists in
master
修改开发环境, 添加chucker抓包
Showing
3 changed files
with
11 additions
and
1 deletions
Show diff stats
build.gradle
1 | buildscript { | 1 | buildscript { |
2 | 2 | ||
3 | 3 | ||
4 | ext { | 4 | ext { |
5 | 5 | ||
6 | 6 | ||
7 | androidId = [ | 7 | androidId = [ |
8 | compileSdkVersion: 32, | 8 | compileSdkVersion: 32, |
9 | minSdkVersion : 24, | 9 | minSdkVersion : 24, |
10 | targetSdkVersion : 32, | 10 | targetSdkVersion : 32, |
11 | versionCode : 1, | 11 | versionCode : 1, |
12 | versionName : "0.0.1" | 12 | versionName : "0.0.1" |
13 | 13 | ||
14 | 14 | ||
15 | ] | 15 | ] |
16 | 16 | ||
17 | 17 | ||
18 | url = [ | 18 | url = [ |
19 | server_url : "http://192.168.3.37:8088", //http 请求指令 | 19 | server_url : "http://192.168.3.144:8088", //http 请求指令 |
20 | server_url_online: "https://mgr.hjx.com", //http 请求指令 | 20 | server_url_online: "https://mgr.hjx.com", //http 请求指令 |
21 | ] | 21 | ] |
22 | 22 | ||
23 | 23 | ||
24 | dependencies = [ | 24 | dependencies = [ |
25 | appcompat : 'androidx.appcompat:appcompat:1.0.0', | 25 | appcompat : 'androidx.appcompat:appcompat:1.0.0', |
26 | constraint : 'androidx.constraintlayout:constraintlayout:1.1.3', | 26 | constraint : 'androidx.constraintlayout:constraintlayout:1.1.3', |
27 | cardview : 'androidx.cardview:cardview:1.0.0', | 27 | cardview : 'androidx.cardview:cardview:1.0.0', |
28 | recyclerview : 'androidx.recyclerview:recyclerview:1.0.0', | 28 | recyclerview : 'androidx.recyclerview:recyclerview:1.0.0', |
29 | material : 'com.google.android.material:material:1.0.0', | 29 | material : 'com.google.android.material:material:1.0.0', |
30 | // 依赖RxAndroid 2X 的依赖库 | 30 | // 依赖RxAndroid 2X 的依赖库 |
31 | // 增加RxJava 2X 的依赖库 | 31 | // 增加RxJava 2X 的依赖库 |
32 | rxandroid : 'io.reactivex.rxjava2:rxandroid:2.0.1', | 32 | rxandroid : 'io.reactivex.rxjava2:rxandroid:2.0.1', |
33 | rxjava : 'io.reactivex.rxjava2:rxjava:2.0.7', | 33 | rxjava : 'io.reactivex.rxjava2:rxjava:2.0.7', |
34 | 34 | ||
35 | // 以下需要使用Retrofit | 35 | // 以下需要使用Retrofit |
36 | //retrofit | 36 | //retrofit |
37 | retrofit : 'com.squareup.retrofit2:retrofit:2.1.0', | 37 | retrofit : 'com.squareup.retrofit2:retrofit:2.1.0', |
38 | //Gson converter | 38 | //Gson converter |
39 | converter : 'com.squareup.retrofit2:converter-gson:2.1.0', | 39 | converter : 'com.squareup.retrofit2:converter-gson:2.1.0', |
40 | //RxJava2 Adapter | 40 | //RxJava2 Adapter |
41 | retrofit2 : 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0', | 41 | retrofit2 : 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0', |
42 | //okhttp | 42 | //okhttp |
43 | okhttp : 'com.squareup.okhttp3:okhttp:3.8.1', | 43 | okhttp : 'com.squareup.okhttp3:okhttp:3.8.1', |
44 | logging : 'com.squareup.okhttp3:logging-interceptor:3.4.1', | 44 | logging : 'com.squareup.okhttp3:logging-interceptor:3.4.1', |
45 | utils : 'com.github.wang-developer:AndroidUtilsDemo:1.0.6', | 45 | utils : 'com.github.wang-developer:AndroidUtilsDemo:1.0.6', |
46 | commons_lang : 'org.apache.commons:commons-lang3:3.7', | 46 | commons_lang : 'org.apache.commons:commons-lang3:3.7', |
47 | commons_compress: 'org.apache.commons:commons-compress:1.19', | 47 | commons_compress: 'org.apache.commons:commons-compress:1.19', |
48 | commons_c_lang : 'commons-lang:commons-lang:2.3', | 48 | commons_c_lang : 'commons-lang:commons-lang:2.3', |
49 | commons_codec : 'commons-codec:commons-codec:1.7', | 49 | commons_codec : 'commons-codec:commons-codec:1.7', |
50 | eventbus : 'org.greenrobot:eventbus:3.2.0', | 50 | eventbus : 'org.greenrobot:eventbus:3.2.0', |
51 | eventbus2 : 'org.simple:androideventbus:1.0.5.1', | 51 | eventbus2 : 'org.simple:androideventbus:1.0.5.1', |
52 | glide : 'com.github.bumptech.glide:glide:4.6.1', | 52 | glide : 'com.github.bumptech.glide:glide:4.6.1', |
53 | permissions : 'com.github.getActivity:XXPermissions:11.6', | 53 | permissions : 'com.github.getActivity:XXPermissions:11.6', |
54 | orcode : 'cn.yipianfengye.android:zxing-library:2.2' | 54 | orcode : 'cn.yipianfengye.android:zxing-library:2.2' |
55 | // push : 'com.umeng.sdk:push:4.1.0', | 55 | // push : 'com.umeng.sdk:push:4.1.0', |
56 | // litepal : 'org.litepal.android:java:3.0.0', | 56 | // litepal : 'org.litepal.android:java:3.0.0', |
57 | 57 | ||
58 | 58 | ||
59 | // AlivcFFmpeg : 'com.aliyun.video.android:AlivcFFmpeg:2.0.0', | 59 | // AlivcFFmpeg : 'com.aliyun.video.android:AlivcFFmpeg:2.0.0', |
60 | 60 | ||
61 | // | 61 | // |
62 | // basequickadapter : 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.34', | 62 | // basequickadapter : 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.34', |
63 | // SwipeDelMenuLayout: 'com.github.mcxtzhang:SwipeDelMenuLayout:V1.3.0', | 63 | // SwipeDelMenuLayout: 'com.github.mcxtzhang:SwipeDelMenuLayout:V1.3.0', |
64 | // flycoTabLayout : 'com.flyco.tablayout:FlycoTabLayout_Lib:2.1.2@aar' | 64 | // flycoTabLayout : 'com.flyco.tablayout:FlycoTabLayout_Lib:2.1.2@aar' |
65 | 65 | ||
66 | 66 | ||
67 | ] | 67 | ] |
68 | } | 68 | } |
69 | 69 | ||
70 | 70 | ||
71 | repositories { | 71 | repositories { |
72 | maven { url 'https://maven.aliyun.com/repository/gradle-plugin' } | 72 | maven { url 'https://maven.aliyun.com/repository/gradle-plugin' } |
73 | maven { url 'https://maven.aliyun.com/repository/google' } | 73 | maven { url 'https://maven.aliyun.com/repository/google' } |
74 | maven { url 'https://maven.aliyun.com/repository/central' } | 74 | maven { url 'https://maven.aliyun.com/repository/central' } |
75 | google() | 75 | google() |
76 | maven { url 'https://maven.aliyun.com/repository/jcenter' } | 76 | maven { url 'https://maven.aliyun.com/repository/jcenter' } |
77 | } | 77 | } |
78 | dependencies { | 78 | dependencies { |
79 | classpath 'com.android.tools.build:gradle:4.2.2' | 79 | classpath 'com.android.tools.build:gradle:4.2.2' |
80 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4' | 80 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4' |
81 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' | 81 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' |
82 | classpath 'com.jakewharton:butterknife-gradle-plugin:10.2.3' | 82 | classpath 'com.jakewharton:butterknife-gradle-plugin:10.2.3' |
83 | classpath "com.alibaba:arouter-register:1.0.2" | 83 | classpath "com.alibaba:arouter-register:1.0.2" |
84 | // NOTE: Do not place your application dependencies here; they belong | 84 | // NOTE: Do not place your application dependencies here; they belong |
85 | // in the individual module build.gradle files | 85 | // in the individual module build.gradle files |
86 | } | 86 | } |
87 | 87 | ||
88 | 88 | ||
89 | } | 89 | } |
90 | 90 | ||
91 | 91 | ||
92 | allprojects { | 92 | allprojects { |
93 | repositories { | 93 | repositories { |
94 | maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' } | 94 | maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' } |
95 | maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' } | 95 | maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' } |
96 | maven { url 'https://jitpack.io' } | 96 | maven { url 'https://jitpack.io' } |
97 | google() | 97 | google() |
98 | maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' } | 98 | maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' } |
99 | } | 99 | } |
100 | } | 100 | } |
101 | task clean(type: Delete) { | 101 | task clean(type: Delete) { |
102 | delete rootProject.buildDir | 102 | delete rootProject.buildDir |
103 | } | 103 | } |
104 | 104 |
libs/common/build.gradle
1 | apply plugin: 'com.android.library' | 1 | apply plugin: 'com.android.library' |
2 | apply from: '../../config.gradle' | 2 | apply from: '../../config.gradle' |
3 | 3 | ||
4 | 4 | ||
5 | def androidId = rootProject.ext.androidId | 5 | def androidId = rootProject.ext.androidId |
6 | def support = rootProject.ext.dependencies | 6 | def support = rootProject.ext.dependencies |
7 | def url = rootProject.ext.url | 7 | def url = rootProject.ext.url |
8 | 8 | ||
9 | 9 | ||
10 | android { | 10 | android { |
11 | compileSdkVersion androidId.compileSdkVersion | 11 | compileSdkVersion androidId.compileSdkVersion |
12 | 12 | ||
13 | 13 | ||
14 | defaultConfig { | 14 | defaultConfig { |
15 | minSdkVersion androidId.minSdkVersion | 15 | minSdkVersion androidId.minSdkVersion |
16 | targetSdkVersion androidId.targetSdkVersion | 16 | targetSdkVersion androidId.targetSdkVersion |
17 | versionCode androidId.versionCode | 17 | versionCode androidId.versionCode |
18 | versionName androidId.versionName | 18 | versionName androidId.versionName |
19 | 19 | ||
20 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | 20 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" |
21 | 21 | ||
22 | } | 22 | } |
23 | 23 | ||
24 | buildTypes { | 24 | buildTypes { |
25 | debug { | 25 | debug { |
26 | minifyEnabled false | 26 | minifyEnabled false |
27 | buildConfigField("String", "SERVER_URL", "\"${url.server_url}\"") | 27 | buildConfigField("String", "SERVER_URL", "\"${url.server_url}\"") |
28 | buildConfigField("String", "APIKey", "\"OmmSqorNFXjVHXlZWhHAyGyQ\"") | 28 | buildConfigField("String", "APIKey", "\"OmmSqorNFXjVHXlZWhHAyGyQ\"") |
29 | buildConfigField("String", "SecretKey", "\"Uwjz4XGi89RN4Mvl5mievKpjqpGgUy6D\"") | 29 | buildConfigField("String", "SecretKey", "\"Uwjz4XGi89RN4Mvl5mievKpjqpGgUy6D\"") |
30 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | 30 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' |
31 | } | 31 | } |
32 | release { | 32 | release { |
33 | minifyEnabled false | 33 | minifyEnabled false |
34 | buildConfigField("String", "SERVER_URL", "\"${url.server_url_online}\"") | 34 | buildConfigField("String", "SERVER_URL", "\"${url.server_url_online}\"") |
35 | buildConfigField("String", "APIKey", "\"OmmSqorNFXjVHXlZWhHAyGyQ\"") | 35 | buildConfigField("String", "APIKey", "\"OmmSqorNFXjVHXlZWhHAyGyQ\"") |
36 | buildConfigField("String", "SecretKey", "\"Uwjz4XGi89RN4Mvl5mievKpjqpGgUy6D\"") | 36 | buildConfigField("String", "SecretKey", "\"Uwjz4XGi89RN4Mvl5mievKpjqpGgUy6D\"") |
37 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | 37 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' |
38 | } | 38 | } |
39 | } | 39 | } |
40 | 40 | ||
41 | compileOptions { | 41 | compileOptions { |
42 | sourceCompatibility JavaVersion.VERSION_1_8 | 42 | sourceCompatibility JavaVersion.VERSION_1_8 |
43 | targetCompatibility JavaVersion.VERSION_1_8 | 43 | targetCompatibility JavaVersion.VERSION_1_8 |
44 | } | 44 | } |
45 | } | 45 | } |
46 | 46 | ||
47 | dependencies { | 47 | dependencies { |
48 | implementation fileTree(include: ['*.jar'], dir: 'libs') | 48 | implementation fileTree(include: ['*.jar'], dir: 'libs') |
49 | 49 | ||
50 | 50 | ||
51 | support.each { k, v -> implementation v } | 51 | support.each { k, v -> implementation v } |
52 | 52 | ||
53 | // 抓包, OkHttp拦截 | ||
54 | def chuckerVersion = "3.5.2" | ||
55 | debugImplementation("com.github.chuckerteam.chucker:library:$chuckerVersion") { | ||
56 | exclude module: 'lifecycle-viewmodel-ktx' | ||
57 | } | ||
58 | releaseImplementation("com.github.chuckerteam.chucker:library-no-op:$chuckerVersion") { | ||
59 | exclude module: 'lifecycle-viewmodel-ktx' | ||
60 | } | ||
53 | 61 | ||
54 | } | 62 | } |
libs/common/src/main/java/com/prws/common/net/OkHttp3Utils.java
1 | package com.prws.common.net; | 1 | package com.prws.common.net; |
2 | 2 | ||
3 | import android.content.Context; | 3 | import android.content.Context; |
4 | import android.net.ConnectivityManager; | 4 | import android.net.ConnectivityManager; |
5 | import android.net.NetworkInfo; | 5 | import android.net.NetworkInfo; |
6 | import android.util.Log; | 6 | import android.util.Log; |
7 | 7 | ||
8 | 8 | ||
9 | import com.chuckerteam.chucker.api.ChuckerInterceptor; | ||
9 | import com.prws.common.CommonApplication; | 10 | import com.prws.common.CommonApplication; |
10 | 11 | ||
11 | import java.io.File; | 12 | import java.io.File; |
12 | import java.io.IOException; | 13 | import java.io.IOException; |
13 | import java.util.List; | 14 | import java.util.List; |
14 | import java.util.concurrent.TimeUnit; | 15 | import java.util.concurrent.TimeUnit; |
15 | 16 | ||
16 | import okhttp3.Cache; | 17 | import okhttp3.Cache; |
17 | import okhttp3.CacheControl; | 18 | import okhttp3.CacheControl; |
18 | import okhttp3.Cookie; | 19 | import okhttp3.Cookie; |
19 | import okhttp3.CookieJar; | 20 | import okhttp3.CookieJar; |
20 | import okhttp3.HttpUrl; | 21 | import okhttp3.HttpUrl; |
21 | import okhttp3.Interceptor; | 22 | import okhttp3.Interceptor; |
22 | import okhttp3.OkHttpClient; | 23 | import okhttp3.OkHttpClient; |
23 | import okhttp3.Request; | 24 | import okhttp3.Request; |
24 | import okhttp3.Response; | 25 | import okhttp3.Response; |
25 | 26 | ||
26 | /** | 27 | /** |
27 | * | 28 | * |
28 | */ | 29 | */ |
29 | 30 | ||
30 | public class OkHttp3Utils { | 31 | public class OkHttp3Utils { |
31 | 32 | ||
32 | private static OkHttpClient mOkHttpClient; | 33 | private static OkHttpClient mOkHttpClient; |
33 | 34 | ||
34 | //设置缓存目录 | 35 | //设置缓存目录 |
35 | private static File cacheDirectory = new File(CommonApplication.getAppContext().getApplicationContext().getCacheDir().getAbsolutePath(), "MyCache"); | 36 | private static File cacheDirectory = new File(CommonApplication.getAppContext().getApplicationContext().getCacheDir().getAbsolutePath(), "MyCache"); |
36 | private static Cache cache = new Cache(cacheDirectory, 10 * 1024 * 1024); | 37 | private static Cache cache = new Cache(cacheDirectory, 10 * 1024 * 1024); |
37 | 38 | ||
38 | 39 | ||
39 | /** | 40 | /** |
40 | * 获取OkHttpClient对象 | 41 | * 获取OkHttpClient对象 |
41 | * | 42 | * |
42 | * @return | 43 | * @return |
43 | */ | 44 | */ |
44 | public static OkHttpClient getOkHttpClient() { | 45 | public static OkHttpClient getOkHttpClient() { |
45 | if (null == mOkHttpClient) { | 46 | if (null == mOkHttpClient) { |
46 | 47 | ||
47 | //同样okhttp3后也使用build设计模式 | 48 | //同样okhttp3后也使用build设计模式 |
48 | mOkHttpClient = new OkHttpClient.Builder() | 49 | mOkHttpClient = new OkHttpClient.Builder() |
49 | //设置一个自动管理cookies的管理器 | 50 | //设置一个自动管理cookies的管理器 |
50 | .cookieJar(new CookiesManager()) | 51 | .cookieJar(new CookiesManager()) |
51 | .cache(cache) | 52 | .cache(cache) |
53 | .addInterceptor(new ChuckerInterceptor.Builder(CommonApplication.getAppContext()).build()) | ||
52 | .addInterceptor(new SignInterceptor()) | 54 | .addInterceptor(new SignInterceptor()) |
53 | //添加拦截器 | 55 | //添加拦截器 |
54 | .addInterceptor(new MyIntercepter()) | 56 | .addInterceptor(new MyIntercepter()) |
55 | .addInterceptor(new LoggingInterceptor()) | 57 | .addInterceptor(new LoggingInterceptor()) |
56 | .addInterceptor(new OkHttpRetryInterceptor.Builder() | 58 | .addInterceptor(new OkHttpRetryInterceptor.Builder() |
57 | // .buildRetryCount(3)//最大重试次数 | 59 | // .buildRetryCount(3)//最大重试次数 |
58 | .buildRetryInterval(0)//重试时间间隔 | 60 | .buildRetryInterval(0)//重试时间间隔 |
59 | .build()) | 61 | .build()) |
60 | //添加网络连接器 | 62 | //添加网络连接器 |
61 | // .addNetworkInterceptor(new CookiesInterceptor(MyApplication.getInstance().getApplicationContext())) | 63 | // .addNetworkInterceptor(new CookiesInterceptor(MyApplication.getInstance().getApplicationContext())) |
62 | //设置请求读写的超时时间 | 64 | //设置请求读写的超时时间 |
63 | .connectTimeout(10, TimeUnit.SECONDS) | 65 | .connectTimeout(10, TimeUnit.SECONDS) |
64 | .writeTimeout(10, TimeUnit.SECONDS) | 66 | .writeTimeout(10, TimeUnit.SECONDS) |
65 | .readTimeout(10, TimeUnit.SECONDS) | 67 | .readTimeout(10, TimeUnit.SECONDS) |
66 | .build(); | 68 | .build(); |
67 | 69 | ||
68 | } | 70 | } |
69 | 71 | ||
70 | 72 | ||
71 | return mOkHttpClient; | 73 | return mOkHttpClient; |
72 | } | 74 | } |
73 | 75 | ||
74 | 76 | ||
75 | /** | 77 | /** |
76 | * 拦截器 | 78 | * 拦截器 |
77 | */ | 79 | */ |
78 | private static class MyIntercepter implements Interceptor { | 80 | private static class MyIntercepter implements Interceptor { |
79 | @Override | 81 | @Override |
80 | public Response intercept(Chain chain) throws IOException { | 82 | public Response intercept(Chain chain) throws IOException { |
81 | Request request = chain.request(); | 83 | Request request = chain.request(); |
82 | if (!isNetworkReachable(CommonApplication.getAppContext().getApplicationContext())) { | 84 | if (!isNetworkReachable(CommonApplication.getAppContext().getApplicationContext())) { |
83 | request = request.newBuilder() | 85 | request = request.newBuilder() |
84 | .cacheControl(CacheControl.FORCE_CACHE)//无网络时只从缓存中读取 | 86 | .cacheControl(CacheControl.FORCE_CACHE)//无网络时只从缓存中读取 |
85 | .build(); | 87 | .build(); |
86 | Log.e("缓存目录====>",cacheDirectory.getAbsolutePath()); | 88 | Log.e("缓存目录====>",cacheDirectory.getAbsolutePath()); |
87 | } | 89 | } |
88 | 90 | ||
89 | Response response = chain.proceed(request); | 91 | Response response = chain.proceed(request); |
90 | if (isNetworkReachable(CommonApplication.getAppContext().getApplicationContext())) { | 92 | if (isNetworkReachable(CommonApplication.getAppContext().getApplicationContext())) { |
91 | int maxAge = 60 * 60; // 有网络时 设置缓存超时时间1个小时 | 93 | int maxAge = 60 * 60; // 有网络时 设置缓存超时时间1个小时 |
92 | response.newBuilder() | 94 | response.newBuilder() |
93 | .removeHeader("Pragma") | 95 | .removeHeader("Pragma") |
94 | .removeHeader("Cache-Control") | 96 | .removeHeader("Cache-Control") |
95 | .header("Cache-Control", "public, max-age=" + maxAge) | 97 | .header("Cache-Control", "public, max-age=" + maxAge) |
96 | .build(); | 98 | .build(); |
97 | } else { | 99 | } else { |
98 | int maxStale = 60 * 60 * 24 * 28; // 无网络时,设置超时为4周 | 100 | int maxStale = 60 * 60 * 24 * 28; // 无网络时,设置超时为4周 |
99 | response.newBuilder() | 101 | response.newBuilder() |
100 | .removeHeader("Pragma") | 102 | .removeHeader("Pragma") |
101 | .removeHeader("Cache-Control") | 103 | .removeHeader("Cache-Control") |
102 | .header("Cache-Control", "public, only-if-cached, max-stale=" + maxStale) | 104 | .header("Cache-Control", "public, only-if-cached, max-stale=" + maxStale) |
103 | .build(); | 105 | .build(); |
104 | } | 106 | } |
105 | return response; | 107 | return response; |
106 | } | 108 | } |
107 | } | 109 | } |
108 | 110 | ||
109 | 111 | ||
110 | /** | 112 | /** |
111 | * 自动管理Cookies | 113 | * 自动管理Cookies |
112 | */ | 114 | */ |
113 | private static class CookiesManager implements CookieJar { | 115 | private static class CookiesManager implements CookieJar { |
114 | private final PersistentCookieStore cookieStore = new PersistentCookieStore(CommonApplication.getAppContext().getApplicationContext()); | 116 | private final PersistentCookieStore cookieStore = new PersistentCookieStore(CommonApplication.getAppContext().getApplicationContext()); |
115 | 117 | ||
116 | @Override | 118 | @Override |
117 | public void saveFromResponse(HttpUrl url, List<Cookie> cookies) { | 119 | public void saveFromResponse(HttpUrl url, List<Cookie> cookies) { |
118 | if (cookies != null && cookies.size() > 0) { | 120 | if (cookies != null && cookies.size() > 0) { |
119 | for (Cookie item : cookies) { | 121 | for (Cookie item : cookies) { |
120 | cookieStore.add(url, item); | 122 | cookieStore.add(url, item); |
121 | } | 123 | } |
122 | } | 124 | } |
123 | } | 125 | } |
124 | 126 | ||
125 | @Override | 127 | @Override |
126 | public List<Cookie> loadForRequest(HttpUrl url) { | 128 | public List<Cookie> loadForRequest(HttpUrl url) { |
127 | List<Cookie> cookies = cookieStore.get(url); | 129 | List<Cookie> cookies = cookieStore.get(url); |
128 | return cookies; | 130 | return cookies; |
129 | } | 131 | } |
130 | } | 132 | } |
131 | 133 | ||
132 | /** | 134 | /** |
133 | * 判断网络是否可用 | 135 | * 判断网络是否可用 |
134 | * | 136 | * |
135 | * @param context Context对象 | 137 | * @param context Context对象 |
136 | */ | 138 | */ |
137 | public static Boolean isNetworkReachable(Context context) { | 139 | public static Boolean isNetworkReachable(Context context) { |
138 | ConnectivityManager cm = (ConnectivityManager) context | 140 | ConnectivityManager cm = (ConnectivityManager) context |
139 | .getSystemService(Context.CONNECTIVITY_SERVICE); | 141 | .getSystemService(Context.CONNECTIVITY_SERVICE); |
140 | NetworkInfo current = cm.getActiveNetworkInfo(); | 142 | NetworkInfo current = cm.getActiveNetworkInfo(); |
141 | if (current == null) { | 143 | if (current == null) { |
142 | return false; | 144 | return false; |
143 | } | 145 | } |
144 | return (current.isAvailable()); | 146 | return (current.isAvailable()); |
145 | } | 147 | } |
146 | } | 148 | } |
147 | 149 |