daily pastebin goal
76%
SHARE
TWEET

Untitled

a guest Dec 10th, 2018 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class MainActivity extends AppCompatActivity {
  2.  
  3.     String Url;
  4.     //Main code
  5.     @Override
  6.     protected void onCreate(Bundle savedInstanceState) {
  7.         super.onCreate(savedInstanceState);
  8.         setContentView(R.layout.activity_main);
  9.  
  10.         //Perform web view
  11.         final WebView webview = (WebView) findViewById(R.id.webview);
  12.         Url = "http://www.youtube.com";
  13.         WebSettings webSettings = webview.getSettings();
  14.         webSettings.setJavaScriptEnabled(true);
  15.         //setContentView(webview);
  16.         webview.setWebViewClient(new WebViewClient());
  17.         webview.loadUrl(Url);
  18.         setDesktopMode(webview, true);
  19.  
  20.         final EditText text1 = (EditText) findViewById(R.id.text1);
  21.         Button ok = (Button)findViewById(R.id.ok);
  22.         ok.setOnClickListener(new Button.OnClickListener() {
  23.             @Override
  24.             public void onClick(View view) {
  25.                 Url = text1.getText().toString();
  26.                 webview.clearCache(true);
  27.                 webview.loadUrl(Url);
  28.                 //webview.reload();
  29.                 setDesktopMode(webview, true);
  30.                 //return;
  31.  
  32.             }
  33.         });
  34.     }
  35.  
  36.     public void setDesktopMode(WebView webView, boolean enabled){
  37.         String newUserAgent = webView.getSettings().getUserAgentString();
  38.         if(enabled){
  39.             try{
  40.                 String ua = webView.getSettings().getUserAgentString();
  41.                 String androidOSString = webView.getSettings().getUserAgentString().substring(ua.indexOf("("), ua.indexOf(")") + 1);
  42.                 newUserAgent = webView.getSettings().getUserAgentString().replace(androidOSString, "(X11; Linux x86_64)");
  43.             } catch (Exception e){
  44.                 e.printStackTrace();
  45.             }
  46.         } else {
  47.             newUserAgent = null;
  48.         }
  49.  
  50.         webView.getSettings().setUserAgentString(newUserAgent);
  51.         webView.getSettings().setUseWideViewPort(enabled);
  52.         webView.getSettings().setLoadWithOverviewMode(enabled);
  53.         webView.reload();
  54.     }
  55.  
  56. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand