Advertisement
Guest User

Untitled

a guest
May 24th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. public static String getDefaultUserAgentString(Context context) {
  2. if (Build.VERSION.SDK_INT >= 17) {
  3. return NewApiWrapper.getDefaultUserAgent(context);
  4. }
  5.  
  6. try {
  7. Constructor<WebSettings> constructor = WebSettings.class.getDeclaredConstructor(Context.class, WebView.class);
  8. constructor.setAccessible(true);
  9. try {
  10. WebSettings settings = constructor.newInstance(context, null);
  11. return settings.getUserAgentString();
  12. } finally {
  13. constructor.setAccessible(false);
  14. }
  15. } catch (Exception e) {
  16. try{
  17. return new WebView(context).getSettings().getUserAgentString();
  18. }catch (Exception e1){
  19. //no WebView is installed
  20. 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" ;
  21. }
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement