of 4.xx google uses okhttp part of the square
public class HttpURLConnectionImpl extends HttpURLConnection { private String defaultUserAgent() { String agent = System.getProperty("http.agent"); return agent != null ? Util.toHumanReadableAscii(agent) : Version.userAgent(); }
https://github.com/square/okhttp/blob/master/okhttp-urlconnection/src/main/java/okhttp3/internal/huc/HttpURLConnectionImpl.java
http://square.imtqy.com/okhttp/
it all depends on the device - which version of os u is used, because api is developing, u can use reflections, but you need to know which field is on a specific api
see https://github.com/square/okhttp/blob/master/CHANGELOG.md
to compare versions of different versions of api: https://android.googlesource.com/platform/external/okhttp/
u can try at the beginning
System.getProperty("http.agent");
edit:
through reflections
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[]{});
same as
String okEngineVersion = System.getProperty("http.agent");
and if you want to worry:
- each class is processed in the same way → as equal (without version control - u can only check the majority value of magic - the java compiler from the class)
- the manifest /system/framework/okhttp.jar does not contain version properties
if u wants the okhttp.internal.Version class, then:
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<String> 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 application crashes from changes in the library, your own version of the library and download classes on the fly or compilation using apk