Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static String getDefaultUserAgentString(Context context) {
- if (Build.VERSION.SDK_INT >= 17) {
- return NewApiWrapper.getDefaultUserAgent(context);
- }
- try {
- Constructor<WebSettings> constructor = WebSettings.class.getDeclaredConstructor(Context.class, WebView.class);
- constructor.setAccessible(true);
- try {
- WebSettings settings = constructor.newInstance(context, null);
- return settings.getUserAgentString();
- } finally {
- constructor.setAccessible(false);
- }
- } catch (Exception e) {
- try{
- return new WebView(context).getSettings().getUserAgentString();
- }catch (Exception e1){
- //no WebView is installed
- return "Mozilla/5.0 (Linux; Android 8.0; SM-G930V Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.125 Mobile Safari/537.36" ;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement