从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();
}
一切都取决于设备 – 你使用的os版本,因为api正在发展,你可以使用反射,但你需要知道特定的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");
如果你想打扰:
>每个班级都以同样的方式对待 – > as equals(没有版本控制 – 你只能查看魔术次要主编号 – 来自类的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