问题
I am trying to create webview
application, in that I have created a webview
to show the desktop site using custom user-agent
. It was working well for the first time , but since second time https://web.whatsapp.com automatically redirect me to https://www.whatsapp.com site instead of web.whatsapp
.
I removed cookies for this app from my mobile then it got connected with web.whatsapp , but when I try to connect it second time, again it redirect me to whatsapp main site.all time this happen with me. So the issue is: if I delete cookies for this app from my mobile of the app it allow me to connect web.whatsapp but only 1 time, if I close the browser and again open it then it again redirect me to whatsapp.com.
I am using the below code
webView = findViewById(R.id.wv);
String ua = "Mozilla/50.0.2 (X11; Linux i686) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/55.0.2883.75(Windows NT 10.0; Win64; x64) Safari/537.31";
webView.getSettings().setUserAgentString(ua);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setSupportZoom(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setDisplayZoomControls(false);
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webView.setScrollbarFadingEnabled(false);
webView.getSettings().setDomStorageEnabled(true);
webView.clearCache(true);
webView.loadUrl(" url string ");
webView.setWebViewClient(new WebViewClient(){
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
final Uri uri = request.getUrl();
return true;
}
@Override
public void onPageFinished(WebView view, final String url) {
webView.clearHistory();
super.onPageFinished(view, url);
}
});
I tried many solution in the forum but no luck.
来源:https://stackoverflow.com/questions/50578112/whatsapp-web-redirecting-issue