刷机后第一次开机时,请求服务器数据会产生异常
W/System.err: javax.net.ssl.SSLHandshakeException: com.android.org.bouncycastle.jce.exception.ExtCertPathValidatorException: Could not validate certificate: null
W/System.err: at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:409)
W/System.err: at okhttp3.internal.connection.RealConnection.connectTls(RealConnection.java:319)
W/System.err: at okhttp3.internal.connection.RealConnection.establishProtocol(RealConnection.java:283)
W/System.err: at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:168)
W/System.err: at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:257)
W/System.err: at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:135)
W/System.err: at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:114)
W/System.err: at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
W/System.err: at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
W/System.err: at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
W/System.err: at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)
W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
W/System.err: at com.umeox.watch.apiclient.http.TokenInterceptor.intercept(TokenInterceptor.java:51)
W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
W/System.err: at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:212)
W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
W/System.err: at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:254)
W/System.err: at okhttp3.RealCall.execute(RealCall.java:92)
这是由于请求Https协议网址,由于需要校验证书。证书过期导致(系统时间错误)
可以通过以下方式同步时间:
一、获取网络建立连接的时间
/**
* 同步网络时间
*/
public void setSystemClockTime() {
try {
URL url1 = new URL("http://www.baidu.com/");
URLConnection conn = url1.openConnection();
conn.connect();
SystemClock.setCurrentTimeMillis(conn.getDate());
} catch (Exception e) {
e.printStackTrace();
}
}
二、通过NTP同步时间TrueTime
以上是针对急于请求服务器数据的情况,比如Launcher应用,一般手机把自动同步时间开关打开就可以解决