I have taken reference to this previously asked question. I have tried doing this
public class MainActivity extends AppCompatActivity {
WebView webview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webview=findViewById(R.id.webview1);
Toast.makeText(MainActivity.this, "Loading...", Toast.LENGTH_SHORT).show();
String newUA= "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) Gecko/20100101 Firefox/4.0";
webview.getSettings().setUserAgentString(newUA);
webview.getSettings().setUseWideViewPort(true);
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebViewClient(new WebViewClient());
webview.loadUrl("https://facebook.com");
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
switch (keyCode) {
case KeyEvent.KEYCODE_BACK:
if (webview.canGoBack()) {
webview.goBack();
} else {
finish();
}
return true;
}
}
return super.onKeyDown(keyCode, event);
}
}
and did what an answer suggested, but as in the comments of one of the answer to the reference question, it asks me to update my browser. My aim is to open the "Whatsapp-Web" desktop site inside my webview. What should I do regarding the browser and any advice regarding opening whatsapp. Thank you in advance.
Edit: This is the new Code that I am trying with a new User Agent
String newUA= "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1";
whatsapp.getSettings().setUserAgentString(newUA);
String DESKTOP_USERAGENT = whatsapp.getSettings().getUserAgentString ();
DESKTOP_USERAGENT = DESKTOP_USERAGENT.replace("Mobile ","");
whatsapp.getSettings().setUserAgentString(DESKTOP_USERAGENT);
whatsapp.getSettings().setJavaScriptEnabled(true);
whatsapp.setWebViewClient(new WebViewClient());
whatsapp.loadUrl("https://web.whatsapp.com/");