2020-08-03 09:11:54 +08:00
|
|
|
|
package com.sl.house_property;
|
|
|
|
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
|
|
import android.app.Application;
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
|
import android.os.StrictMode;
|
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
2021-12-08 15:27:07 +08:00
|
|
|
|
import androidx.multidex.MultiDex;
|
|
|
|
|
|
|
2020-08-11 14:48:10 +08:00
|
|
|
|
import com.lzy.ninegrid.NineGridView;
|
2021-03-24 23:32:14 +08:00
|
|
|
|
import com.lzy.okgo.OkGo;
|
|
|
|
|
|
import com.lzy.okgo.cache.CacheEntity;
|
|
|
|
|
|
import com.lzy.okgo.cache.CacheMode;
|
|
|
|
|
|
import com.lzy.okgo.cookie.CookieJarImpl;
|
|
|
|
|
|
import com.lzy.okgo.cookie.store.DBCookieStore;
|
|
|
|
|
|
import com.lzy.okgo.https.HttpsUtils;
|
|
|
|
|
|
import com.lzy.okgo.interceptor.HttpLoggingInterceptor;
|
|
|
|
|
|
import com.lzy.okgo.model.HttpHeaders;
|
|
|
|
|
|
import com.lzy.okgo.model.HttpParams;
|
2021-03-10 23:48:19 +08:00
|
|
|
|
import com.sl.house_property.db.dao.DataBaseHelper;
|
2020-09-07 10:05:06 +08:00
|
|
|
|
import com.tencent.bugly.Bugly;
|
2020-08-11 14:48:10 +08:00
|
|
|
|
|
2021-03-24 23:32:14 +08:00
|
|
|
|
import java.security.cert.CertificateException;
|
|
|
|
|
|
import java.security.cert.X509Certificate;
|
2020-08-03 09:11:54 +08:00
|
|
|
|
import java.util.LinkedList;
|
|
|
|
|
|
import java.util.List;
|
2021-03-24 23:32:14 +08:00
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
import java.util.logging.Level;
|
2020-08-03 09:11:54 +08:00
|
|
|
|
|
2021-03-24 23:32:14 +08:00
|
|
|
|
import javax.net.ssl.HostnameVerifier;
|
|
|
|
|
|
import javax.net.ssl.SSLSession;
|
|
|
|
|
|
import javax.net.ssl.X509TrustManager;
|
|
|
|
|
|
|
2021-04-16 16:36:35 +08:00
|
|
|
|
import cn.jpush.android.api.JPushInterface;
|
2021-03-24 23:32:14 +08:00
|
|
|
|
import okhttp3.OkHttpClient;
|
2020-08-03 09:11:54 +08:00
|
|
|
|
import fm.jiecao.jcvideoplayer_lib.JCVideoPlayerStandard;
|
2020-08-11 14:48:10 +08:00
|
|
|
|
import utils.NineImageLoader;
|
2020-08-03 09:11:54 +08:00
|
|
|
|
//import cn.jpush.im.android.api.JMessageClient;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Created by 90432 on 2018/1/15.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2021-12-13 15:09:32 +08:00
|
|
|
|
public class MyApplication extends Application {
|
|
|
|
|
|
//private static final String TAG = "JIGUANG-Example";
|
2020-08-03 09:11:54 +08:00
|
|
|
|
private static final String TAG = MyApplication.class.getSimpleName();
|
|
|
|
|
|
public static Context context;
|
2021-12-13 15:09:32 +08:00
|
|
|
|
protected static MyApplication instance;
|
2020-08-03 09:11:54 +08:00
|
|
|
|
public JCVideoPlayerStandard VideoPlaying;
|
2021-12-13 15:09:32 +08:00
|
|
|
|
|
|
|
|
|
|
/* private HttpNet httpNet;
|
|
|
|
|
|
public static Handler getTheErrorHandler;
|
|
|
|
|
|
public static boolean mainonce;
|
2020-08-03 09:11:54 +08:00
|
|
|
|
|
|
|
|
|
|
*/
|
2021-12-13 15:09:32 +08:00
|
|
|
|
public static Context getContext() {
|
|
|
|
|
|
return context;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2021-03-24 23:32:14 +08:00
|
|
|
|
|
2021-12-13 15:09:32 +08:00
|
|
|
|
@Override
|
|
|
|
|
|
protected void attachBaseContext(Context base) {
|
|
|
|
|
|
super.attachBaseContext(base);
|
|
|
|
|
|
MultiDex.install(this);
|
|
|
|
|
|
}
|
2020-08-03 09:11:54 +08:00
|
|
|
|
|
|
|
|
|
|
public static MyApplication getApp() {
|
|
|
|
|
|
return instance;
|
|
|
|
|
|
}
|
2021-12-13 15:09:32 +08:00
|
|
|
|
|
|
|
|
|
|
public void existActivitys() {
|
|
|
|
|
|
for (Activity act : activityList) {
|
2020-08-03 09:11:54 +08:00
|
|
|
|
act.finish();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-12-13 15:09:32 +08:00
|
|
|
|
public void addActivitys(Activity activity) {
|
2020-08-03 09:11:54 +08:00
|
|
|
|
activityList.add(activity);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private List<Activity> activityList = new LinkedList<Activity>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void onCreate() {
|
|
|
|
|
|
Log.d(TAG, "[ExampleApplication] onCreate");
|
|
|
|
|
|
super.onCreate();
|
|
|
|
|
|
instance = this;
|
2021-03-24 23:32:14 +08:00
|
|
|
|
initOkGo();
|
2021-12-13 15:09:32 +08:00
|
|
|
|
|
2020-08-21 13:39:24 +08:00
|
|
|
|
// CrashHandler crashHandler = CrashHandler.getInstance();
|
|
|
|
|
|
// crashHandler.init(this);
|
2021-12-13 15:09:32 +08:00
|
|
|
|
if (getSharedPreferences("first", Context.MODE_PRIVATE).getInt("first", 0) == 1) {
|
|
|
|
|
|
JPushInterface.init(this);
|
|
|
|
|
|
JPushInterface.setDebugMode(false);
|
|
|
|
|
|
Bugly.init(this, "d45325664f", false);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-25 15:15:11 +08:00
|
|
|
|
// System.setProperty("http.proxyHost", "haotian.hoheng.cn");
|
|
|
|
|
|
// System.setProperty("http.proxyPort", "8080");
|
2020-08-03 09:11:54 +08:00
|
|
|
|
|
|
|
|
|
|
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
|
|
|
|
|
|
StrictMode.setVmPolicy(builder.build());
|
2020-08-11 14:48:10 +08:00
|
|
|
|
NineGridView.setImageLoader(new NineImageLoader());
|
2020-08-03 09:11:54 +08:00
|
|
|
|
|
2021-03-10 23:48:19 +08:00
|
|
|
|
DataBaseHelper.initOrmLite(this);
|
2020-08-03 09:11:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static final String MESSAGE_RECEIVED_ACTION = "com.example.jpushdemo.MESSAGE_RECEIVED_ACTION";
|
|
|
|
|
|
public static final String KEY_MESSAGE = "message";
|
|
|
|
|
|
public static final String KEY_EXTRAS = "extras";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void exit() {
|
|
|
|
|
|
for (Activity act : activityList) {
|
|
|
|
|
|
act.finish();
|
|
|
|
|
|
}
|
|
|
|
|
|
System.exit(0);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-03-24 23:32:14 +08:00
|
|
|
|
private void initOkGo() {
|
|
|
|
|
|
//---------这里给出的是示例代码,告诉你可以这么传,实际使用的时候,根据需要传,不需要就不传-------------//
|
|
|
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
|
headers.put("commonHeaderKey1", "commonHeaderValue1"); //header不支持中文,不允许有特殊字符
|
|
|
|
|
|
headers.put("commonHeaderKey2", "commonHeaderValue2");
|
|
|
|
|
|
HttpParams params = new HttpParams();
|
|
|
|
|
|
params.put("commonParamsKey1", "commonParamsValue1"); //param支持中文,直接传,不要自己编码
|
|
|
|
|
|
params.put("commonParamsKey2", "这里支持中文参数");
|
|
|
|
|
|
//----------------------------------------------------------------------------------------//
|
|
|
|
|
|
|
|
|
|
|
|
OkHttpClient.Builder builder = new OkHttpClient.Builder();
|
|
|
|
|
|
//log相关
|
|
|
|
|
|
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor("OkGo");
|
|
|
|
|
|
loggingInterceptor.setPrintLevel(HttpLoggingInterceptor.Level.BODY); //log打印级别,决定了log显示的详细程度
|
|
|
|
|
|
loggingInterceptor.setColorLevel(Level.INFO); //log颜色级别,决定了log在控制台显示的颜色
|
|
|
|
|
|
builder.addInterceptor(loggingInterceptor); //添加OkGo默认debug日志
|
|
|
|
|
|
//第三方的开源库,使用通知显示当前请求的log,不过在做文件下载的时候,这个库好像有问题,对文件判断不准确
|
|
|
|
|
|
//builder.addInterceptor(new ChuckInterceptor(this));
|
|
|
|
|
|
|
|
|
|
|
|
//超时时间设置,默认60秒
|
|
|
|
|
|
builder.readTimeout(OkGo.DEFAULT_MILLISECONDS, TimeUnit.MILLISECONDS); //全局的读取超时时间
|
|
|
|
|
|
builder.writeTimeout(OkGo.DEFAULT_MILLISECONDS, TimeUnit.MILLISECONDS); //全局的写入超时时间
|
|
|
|
|
|
builder.connectTimeout(OkGo.DEFAULT_MILLISECONDS, TimeUnit.MILLISECONDS); //全局的连接超时时间
|
|
|
|
|
|
|
|
|
|
|
|
//自动管理cookie(或者叫session的保持),以下几种任选其一就行
|
|
|
|
|
|
//builder.cookieJar(new CookieJarImpl(new SPCookieStore(this))); //使用sp保持cookie,如果cookie不过期,则一直有效
|
|
|
|
|
|
builder.cookieJar(new CookieJarImpl(new DBCookieStore(this))); //使用数据库保持cookie,如果cookie不过期,则一直有效
|
|
|
|
|
|
//builder.cookieJar(new CookieJarImpl(new MemoryCookieStore())); //使用内存保持cookie,app退出后,cookie消失
|
|
|
|
|
|
|
|
|
|
|
|
//https相关设置,以下几种方案根据需要自己设置
|
|
|
|
|
|
//方法一:信任所有证书,不安全有风险
|
|
|
|
|
|
HttpsUtils.SSLParams sslParams1 = HttpsUtils.getSslSocketFactory();
|
|
|
|
|
|
//方法二:自定义信任规则,校验服务端证书
|
|
|
|
|
|
HttpsUtils.SSLParams sslParams2 = HttpsUtils.getSslSocketFactory(new SafeTrustManager());
|
|
|
|
|
|
//方法三:使用预埋证书,校验服务端证书(自签名证书)
|
|
|
|
|
|
//HttpsUtils.SSLParams sslParams3 = HttpsUtils.getSslSocketFactory(getAssets().open("srca.cer"));
|
|
|
|
|
|
//方法四:使用bks证书和密码管理客户端证书(双向认证),使用预埋证书,校验服务端证书(自签名证书)
|
|
|
|
|
|
//HttpsUtils.SSLParams sslParams4 = HttpsUtils.getSslSocketFactory(getAssets().open("xxx.bks"), "123456", getAssets().open("yyy.cer"));
|
|
|
|
|
|
builder.sslSocketFactory(sslParams1.sSLSocketFactory, sslParams1.trustManager);
|
|
|
|
|
|
//配置https的域名匹配规则,详细看demo的初始化介绍,不需要就不要加入,使用不当会导致https握手失败
|
|
|
|
|
|
builder.hostnameVerifier(new SafeHostnameVerifier());
|
|
|
|
|
|
|
|
|
|
|
|
// 其他统一的配置
|
|
|
|
|
|
// 详细说明看GitHub文档:https://github.com/jeasonlzy/
|
|
|
|
|
|
OkGo.getInstance().init(this) //必须调用初始化
|
|
|
|
|
|
.setOkHttpClient(builder.build()) //建议设置OkHttpClient,不设置会使用默认的
|
|
|
|
|
|
.setCacheMode(CacheMode.NO_CACHE) //全局统一缓存模式,默认不使用缓存,可以不传
|
|
|
|
|
|
.setCacheTime(CacheEntity.CACHE_NEVER_EXPIRE) //全局统一缓存时间,默认永不过期,可以不传
|
|
|
|
|
|
.setRetryCount(3); //全局统一超时重连次数,默认为三次,那么最差的情况会请求4次(一次原始请求,三次重连请求),不需要可以设置为0
|
|
|
|
|
|
// .addCommonHeaders(headers) //全局公共头
|
|
|
|
|
|
// .addCommonParams(params); //全局公共参数
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 这里只是我谁便写的认证规则,具体每个业务是否需要验证,以及验证规则是什么,请与服务端或者leader确定
|
|
|
|
|
|
* 这里只是我谁便写的认证规则,具体每个业务是否需要验证,以及验证规则是什么,请与服务端或者leader确定
|
|
|
|
|
|
* 这里只是我谁便写的认证规则,具体每个业务是否需要验证,以及验证规则是什么,请与服务端或者leader确定
|
|
|
|
|
|
* 重要的事情说三遍,以下代码不要直接使用
|
|
|
|
|
|
*/
|
|
|
|
|
|
private class SafeTrustManager implements X509TrustManager {
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
|
|
|
|
|
|
try {
|
|
|
|
|
|
for (X509Certificate certificate : chain) {
|
|
|
|
|
|
certificate.checkValidity(); //检查证书是否过期,签名是否通过等
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
throw new CertificateException(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public X509Certificate[] getAcceptedIssuers() {
|
|
|
|
|
|
return new X509Certificate[0];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 这里只是我谁便写的认证规则,具体每个业务是否需要验证,以及验证规则是什么,请与服务端或者leader确定
|
|
|
|
|
|
* 这里只是我谁便写的认证规则,具体每个业务是否需要验证,以及验证规则是什么,请与服务端或者leader确定
|
|
|
|
|
|
* 这里只是我谁便写的认证规则,具体每个业务是否需要验证,以及验证规则是什么,请与服务端或者leader确定
|
|
|
|
|
|
* 重要的事情说三遍,以下代码不要直接使用
|
|
|
|
|
|
*/
|
|
|
|
|
|
private class SafeHostnameVerifier implements HostnameVerifier {
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public boolean verify(String hostname, SSLSession session) {
|
|
|
|
|
|
//验证主机名是否匹配
|
|
|
|
|
|
//return hostname.equals("server.jeasonlzy.com");
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-03 09:11:54 +08:00
|
|
|
|
}
|