Show whatsapp barcode webpage in webview - android

I am trying to show this link in android app in webview but the web loads in android device is different from showing in Google Chrome.
Whatsapp link is here :https://web.whatsapp.com/
I am using this code in android to load the above page but it does not load the same page.
mWebView .loadUrl("https://web.whatsapp.com/");// https://tekdude.blogspot.in/");
mWebView.getSettings().setBuiltInZoomControls(true);
mWebView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
setContentView(mWebView );

You can Use This Code, It Worked For me!!
Copy this code to inside OnCreate Method!! You can edit code according to your requirement.
webView.loadUrl(YOUR URL HERE);
webView.setWebViewClient(new WebViewClient());
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setUseWideViewPort(true);
webView.setWebChromeClient(new WebChromeClient());
webView.getSettings().setUserAgentString("Mozilla/5.0 (Linux; Win64; x64; rv:46.0) Gecko/20100101 Firefox/68.0");
webView.getSettings().setGeolocationEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setDatabaseEnabled(true);
webView.getSettings().setSupportMultipleWindows(true);
webView.getSettings().setAppCacheEnabled(true);
webView.getSettings().setNeedInitialFocus(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
//webView.getSettings().setBlockNetworkLoads(true);
webView.getSettings().setBlockNetworkImage(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.setInitialScale(100);

You can try with changing user agent of your web view.
Example:
String newUA= "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) Gecko/20100101 Firefox/4.0";
mWebView.getSettings().setUserAgentString(newUA);
Check this link
Setting WebView to view Desktop Site and Not Mobile Site

Change the user agent of webview
like
String newUA= "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) Gecko/20100101 Firefox/4.0";
mWebView.getSettings().setUserAgentString(newUA);
Alternatively you can also change the settings without changing user agent
webView = (WebView)findViewById(R.id.webView1);
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);

Related

Difference between Chrome Custom Tabs and WebView

I'm using a webview to open a website. The problem I'm getting is after user clicks on a button, it always get stuck to the Loading dialog and doesn't show the expected results. But in Google Chrome or custom tabs, it works perfectly fine. I'm not overriding onPageFinished(), onPageStarted() or any other webview method, they are as it is. These are my webview settings:
webView.getSettings().setLoadsImagesAutomatically(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setDisplayZoomControls(false);
webView.getSettings().setSupportMultipleWindows(true);
WebSettings settings = webView.getSettings();
settings.setDomStorageEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setAllowUniversalAccessFromFileURLs(true);
settings.setAllowFileAccessFromFileURLs(true);
settings.setLoadWithOverviewMode(true);
settings.setUseWideViewPort(true);
settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
String newUA= "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:59.0) Gecko/20100101 Firefox/59.0";
webView.getSettings().setUserAgentString(newUA);
webView.clearFormData();
webView.getSettings().setSavePassword(false);
webView.getSettings().setSaveFormData(false);
webView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
webView.setScrollbarFadingEnabled(true);
Just wanted to know what settings could be different in custom tabs and my webview that's causing the issue. And I think it's probably not possible but still asking is there any way to imitate the browser settings of custom tabs for the webview so that I can check if it works that way

Unable to open angular 4 app in a webview

I am trying to open
http://admin.aquateams.com
in android webview but it's showing white screen.
Do I need any polyfill for this ??
Here is webview code for android:
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webView.setScrollbarFadingEnabled(false);
webView.getSettings().setBuiltInZoomControls(true);
webView.loadUrl(String.valueOf("http://admin.aquateams.com")));
var myWebView = page.getViewById("my-web-view");
myWebView.android.getSettings().setJavaScriptEnabled(true);
myWebView.android.getSettings().setAppCacheEnabled(true);
myWebView.android.getSettings().setDomStorageEnabled(true);

Video player not work in WebView

i need help, my WebView not show website's video player(black square)
But, it is working on phone browser.
Also, i have tried to use some advanced webview from github, same result(balck square).
This my code
webView = (WebView) findViewById(R.id.webview);
swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_layout);
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setDomStorageEnabled(true);
settings.setAppCacheEnabled(true);
settings.setDatabaseEnabled(true);
settings.setSupportZoom(true);
settings.setDisplayZoomControls(true);
settings.setBuiltInZoomControls(true);
settings.setAppCachePath(getApplicationContext().getFilesDir().getAbsolutePath() + "/cache");
settings.setDatabaseEnabled(true);
settings.setDatabasePath(getApplicationContext().getFilesDir().getAbsolutePath() + "/databases");
webView.getSettings().setUserAgentString("wp-android-native");
//webView.getSettings().setUserAgentString("Mozilla/5.0 (Linux; Android 4.1.1; HTC One X Build/JRO03C) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.58 Mobile Safari/537.31");
webView.setWebViewClient(new WebViewClient());
webView.setWebChromeClient(new WebChromeClient());
//webView.setInitialScale(100);
webView.loadUrl("http://onlinemoviesbox.com");
Can you please comment below line and check once , am able to play youtube video properly
// webView.getSettings().setUserAgentString("wp-android-native");

How to autoplay youtube videos in Android WebChromeClient

I have created a simple APK for Android that uses WebChromeClient
mWebChromeClient = new myWebChromeClient();
webView.setWebChromeClient(mWebChromeClient);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setPluginState(WebSettings.PluginState.ON);
webView.getSettings().setAppCacheEnabled(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setSaveFormData(true);
webView.loadUrl("http://example.com/embed.php");
I have set the user agent to desktop browser
String ua = "Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1";
webView.getSettings().setUserAgentString(ua);
I added hardware=accelerated to the manifest
android:hardwareAccelerated="true"
Still, I am unable to get the youtube autoplay to work.
One clue is when I go to this URL in my app https://www.youtube.com/html5 it states that "The default player is currently used"
How can I get the embedded youtube video to autoplay in my WebChromeClient?
I have control over both the APK and the html page where the youtube video is embeded, so a solution for either end would work for me!

Why Google map website is acting weird on webview Android?

I'm trying to load maps.google.com when user click a button with this url
http://maps.google.com/maps?saddr=40.702297,-73.796015&daddr=40.73682,-73.989937&mrsp=0,1
It works as I expected, but when I click
It load only partial of screen(not cover all my screen).
NOTE: I tried to load the same url in browser of emulator, everything is working fine.
Here is setting for the webview that I used to load a web:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.webview_layout);
this.webview = (WebView)findViewById(R.id.myWebview);
WebSettings settings = webview.getSettings();
settings.setJavaScriptEnabled(true);
settings.setBuiltInZoomControls(true);
settings.setSupportZoom(true);
webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webview.getSettings().setLoadWithOverviewMode(true);
webview.getSettings().setUseWideViewPort(true);
//....follow by normal setup of webview.setWebViewClient
}
I found a solution for this problem. In my webview I used a line of code in order to load Twitter website (without this line it will only load a white screen)
webSettings.setUserAgentString("Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3");

Categories

Resources