need to re-wrap text in webview when zooming - android

I am using android webview to show an article .
I need to re-wrap the text whenever the user make a zoom .
I'm using android lollipop .
I found this solution but it is not working for me ?
String userAgent = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) Gecko/20100101 Firefox/4.0";
settings.setUserAgentString(userAgent);
Any trick to do that?
Is there is a way to reload the webview whenever the user make a zoom so it will be loaded wrapped to the new size?

You have to do that in javascript function and call that through the javascript client of webview.
for details visit:
android webview basics

Related

Whats app doesn't support Webview android

I want to use whats app in Webview android. I've already tried to set user agent but it didn't help.
Is there any way that whats app recognize webview as Chrome browser.
String newUA= "";
newUA= "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.181 Safari/537.36";
binding.webView.getSettings().setJavaScriptEnabled(true);
binding.webView.loadUrl("https://web.whatsapp.com/");
binding.webView.getSettings().setUserAgentString(newUA);
try to set User Agent BEFORE calling URL load (make all settings-related calls before any page load try)

Webiew load URL issue

This is my url that I want to open in webview but its show different UI rather than the chrome or mozila browser.
http://www.nigeriatoday.ng/
Try to open it in webview and browser and you know the difference.
I need same like browser. Please help me. It would be appreciatable.
WebSettings settings = webvw.getSettings();
webvw.setWebViewClient(new WebViewClient());
webvw.setWebChromeClient(new WebChromeClient());
webvw.getSettings().setJavaScriptEnabled(true);
webvw.getSettings().setJavaScriptCanOpenWindowsAutomatically(false);
webvw.loadUrl(Url);
Thanks
As Murat said, You have different look and feel for Mobile version and desktop version.
If you have any specific requirement that you need to display Web content with desktop version on webview, then you can use below code.
String ua = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) Gecko/20100101 Firefox/4.0";
webvw.getSettings().setUserAgentString(ua);
You can see below output...

Lollipop WebView text wrapping

I've used Android WebView component in many projects, but after updating to lollipop I have a major problem:
Pinch zooming text the will not re-wrap it, it just zooms in!
What can I do to re-enabled this feature which was working pretty well on KitKat and below?
This worked for me, tested on Sony Xperia Z, Android 5.0.1.
String userAgent = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) Gecko/20100101 Firefox/4.0";
webView.getSettings().setUserAgentString(userAgent);

Android, webview user agent vs browser user agent

I'm building my website and I want to know whether the user is using Android's browser or an app with a webview.
is it possible ??
As per Chrome dev docs: "If you’re attempting to differentiate between the WebView and Chrome for Android, you should look for the presence of the Version/X.X string in the WebView user-agent string."
FROM: http://googlewebmastercentral.blogspot.com/2011/03/mo-better-to-also-detect-mobile-user.html
With a User-Agent like this:
Mozilla/5.0 (Linux; U; Android 3.0; en-us; Xoom Build/HRI39) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13
since there is no “mobile” string, serve this user the desktop version (or a version customized for Android large-screen touch devices). The User-Agent tells us they’re coming from a large-screen device, the XOOM tablet.
On the other hand, this User-Agent:
Mozilla/5.0 (Linux; U; Android 2.2.1; en-us; Nexus One Build/FRG83) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1
contains “mobile” and “android,” so serve the web surfer on this Nexus One the mobile experience!
FROM https://stackoverflow.com/a/7327201
it looks like the User-Agent is the same in webview as in the default mobile browser
FYI: This can't be done with user agents, however it can be detected. Android's web views send an addition header "X-Requested-With". The value of this header will be the application's name space that is running the webview.
For Example Dolphin browser sends: "mobi.mgeek.TunnyBrowser"
My test app sent: "com.jamestymann.identifyawebview"
The standard browser actually does not send this header at all, so it is pretty easy to detect these.
I have two caveats though:
"X-Requested-With" is a standard header and could potentially be sent from full blown webpages/browsers from desktops. (For example this is used to detect ajax calls with these values "X-Requested-With XMLHttpRequest")
Most google play store browsers use webviews to display webpages. Even though these are full blown browsers, they will still send this header. So if your intent is to disable this feature you may want to be careful as you may be disabling peoples default browsers.
For more current information, look here https://developer.chrome.com/multidevice/user-agent The lolipop and newer devices include wv) in the UserAgent.
You can used below code for checked android webview or browser.
public static bool is_mobile_and_webview()
{
return System.Web.HttpContext.Current.Request.Browser.IsMobileDevice && System.Web.HttpContext.Current.Request.UserAgent.Contains("; wv");
}
yes and you can optimize your website by adding these meta tags
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />
<meta name="HandheldFriendly" content="True" />
you can find more information here http://learnthemobileweb.com/2009/07/mobile-meta-tags/
I use this serverside, to access info about client' browser (agent) in PHP
...
$_SERVER['HTTP_USER_AGENT']; // Different browsers ...
...
this boilerplate can be interpreted - hence you will know the agent ...
on client side - navigator.userAgent

android mobile twitter page in webview not opening?

I am trying to open twitter page begining with https in webview in android. But it is not opening and blank screen is coming with continous loading. Screen shot is below
Edit: In main webview I have link to twitter page https://twitter.com/mytwitterpage. On clicking that link that twitter url is opening in webview. I noticed that onPageFinished method of WebViewClient is called 2 times one time for https://twitter.com/mytwitterpage and second time for https://mobile.twitter.com/#!/mytwitterpage.
Anyone know what is wrong here?
Thanks in advance.
Ok done by adding below line in my code
webView.getSettings().setUserAgentString("Mozilla/5.0 (Linux; U; Android 2.0; en-us; Droid Build/ESD20) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17");
I got it from this post at stackoverflow Problems loading mobile.twitter in webview.
wv.getSettings().setDomStorageEnabled(true);
This worked for me!
Are you hitting a https:// page? If so, try setting a WebViewClient on your webview and override onReceivedSslError and see if there something wrong.
Twitter changed some certificate stuff recently, if you're hitting twitter.com/... try hitting api.twitter.com/...
Just add this code below webview. It solved my problem.
webView.getSettings().setJavaScriptEnabled(true);
webView.addJavascriptInterface(this, "TwitterDownloader");

Categories

Resources