okhttp 对应java版本_java – Android |在运行时获取OkHTTP库版本
從4.xx谷歌正在使用okhttp部分的平方
/**
* This implementation uses HttpEngine to send requests and receive responses. This class may use
* multiple HttpEngines to follow redirects, authentication retries, etc. to retrieve the final
* response body.
*
*
What does 'connected' mean?
This class inherits a {@code connected} field from the* superclass. That field is not used to indicate whether this URLConnection is
* currently connected. Instead, it indicates whether a connection has ever been attempted. Once a
* connection has been attempted, certain properties (request header fields, request method, etc.)
* are immutable.
*/
public class HttpURLConnectionImpl extends HttpURLConnection {
private String defaultUserAgent() {
String agent = System.getProperty("http.agent");
return agent != null ? Util.toHumanReadableAscii(agent) : Version.userAgent();
}
一切都取決于設(shè)備 – 你使用的os版本,因?yàn)閍pi正在發(fā)展,你可以使用反射,但你需要知道特定的api是什么字段
你可以在一開始就試試
System.getProperty("http.agent");
編輯:
通過反思
HttpURLConnection connection = (HttpURLConnection) new URL("http://google.com")
.openConnection();
Method method = connection.getClass().getDeclaredMethod("defaultUserAgent");
method.setAccessible(true);
String okEngineVersion = (String) method.invoke(connection, new Object[]{});
與…一樣
String okEngineVersion = System.getProperty("http.agent");
如果你想打擾:
>每個(gè)班級都以同樣的方式對待 – > as equals(沒有版本控制 – 你只能查看魔術(shù)次要主編號 – 來自類的java編譯器版本)
> /system/framework/okhttp.jar的清單不包含版本屬性
如果你想要okhttp.internal.Version類,那么:
File file = new File("/system/framework/okhttp.jar");
// using javaxt-core lib
Jar jar = new Jar(file);
jar.getVersion();
// load dex
DexFile dexfile = DexFile.loadDex(file.getAbsolutePath(),
File.createTempFile("opt", "dex", _context.getCacheDir()).getPath(), 0);
Enumeration dexEntries = dexfile.entries();
ClassLoader systemClassLoader = DexClassLoader.getSystemClassLoader();
while (dexEntries.hasMoreElements()) {
String className = dexEntries.nextElement();
Class> aClass = systemClassLoader.loadClass(className);
}
conclusion: If you want to avoid crash of app from library changes delivery own version of library and load classes on the fly or compile with apk
總結(jié)
以上是生活随笔為你收集整理的okhttp 对应java版本_java – Android |在运行时获取OkHTTP库版本的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java 易变变量_提高java编程质量
- 下一篇: mysql 回表 覆盖索引_MySQL