android mobile twitter page in webview not opening? - android

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");

Related

How to request desktop in a webview?

I searched Google and stack exchange and found about 15 different solutions, none of which work. They either throw syntax errors upon compiling, or they just don't work on the website I'm requesting. (Tradingview.com/chart)
When I go to my target website in chrome and click Request desktop, it works fine. In the webview in the app I'm building, it doesn't work. Google displays as desktop, but my target site does not. However, it does display properly in chrome or Firefox, just not my app.
What I tried:
Every solution provided here: Setting WebView to view Desktop Site and Not Mobile Site
Including this library https://github.com/delight-im/Android-AdvancedWebView/blob/master/README.md
This
How to open desktop site in webview in android
That
How to load Desktop view instead of mobile view in webview
The other
setUserAgentString in Android webview has no effect on HTTP header used in loadURL()
Most of those don't cause any change (on my target site), while a few of them throw syntax errors, sometimes up to 13 of them.
I tend to see comments being left saying something to the effect of, "Contact the website owner to make them change their site." That's not an acceptable solution, and is unhelpful without further explanation. How is it that in chrome, Firefox, Opera, etc. I'm well able to see a desktop version of the page, but it isn't working on the webview? This needs to be explained if the only answer is that it's"the website's fault contact the owner."
Right now I've got this in here,
WebView webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient());
webView.getSettings().setUserAgentString("Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) Gecko/20100101 Firefox/57.0");
webView.loadUrl("http://facebook.com");
This works fine on Facebook.com for example, but not TradingView.
After much trial and error, I came to a solution. This isn't perfect, but much closer. (Maybe comments can help correct my code where I've fallen short)
webview_chart.getSettings().setLoadWithOverviewMode(true);
webview_chart.setInitialScale(200);
webview_chart.getSettings().setUseWideViewPort(false);
webview_chart.getSettings().setMinimumFontSize(16);
String newUA= "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.45 Safari/535.19";
webview_chart.getSettings().setUserAgentString(newUA);
webview_chart.loadUrl("http://tradingview.com/chart");
What this seems to do is spoof a larger screen size, which causes responsive design to send desktop version rather than mobile. It's not perfect, as you can see I have to adjust minimum font size up so things are readable, and on smaller screens it still doesn't work.
But that's the reason you can send desktop headers and still get a mobile site.
(I haven't found an explanation like this anywhere else, so I think it can be helpful to others having this same problem)

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...

need to re-wrap text in webview when zooming

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

Android Webview issue for Twitter even with DomStorageEnabled enabled

I have tested the following issue on Galaxy Note 2.3, Sony tablet 3.2 as well as Galaxy Y 2.3 and the issue is 100% reproducable. As suggested on many threads , webview.getSettings().setDomStorageEnabled(true); does the trick. But i am observing that first time when the Webview loads twitter.com , its going blank . Then if i say webview.reload() or again call load Url then twitter loads correctly every time until i exit the app (Preferably Force stop from settings) . This issue is happening for all sites which give WebConsole error. If i reload the same site , then its loading correctly. Is anyone having the same issue ?
Following is a small snippet of code i use.
webview = new Webview(activity.context);
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setBuiltInZoomControls(true);
webview.getSettings().setDomStorageEnabled(true);
webview.loadUrl("http://www.twitter.com");
Hardcoding the Useragent as suggested on other threads solved the problem
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");
What will be the disadvantages of this dirty trick ? Will it affect the sites loading on a tablet ?
Will users be able to go to the desktop site if they want to ?

Specific link not loading in WebView on some droids

I have an app out which displays this link in a web view when a user presses e-mail:
https://marauder.millersville.edu/mail/index.pl
I developed the app on an Droid X, and on my phone the link loads fine, but I have had reports from users who have an Incredible & Droid X that the link loads a blank screen.
I have tested it myself on a friends Incredible, and it indeed only loads a white screen, but I have have tested it on various other android devices and its loads fine.
And every other links also loads fine on the Incredible. I am assuming it has something to do with the SSL, being a https. I had troubles with this link on an iPhone but was able to fix it. What puzzles me is why it works fine on some devices and not on others..
Anyone have any ideas or suggestions? Thanks!
Here is how I am setting up my web view:
// setup webview
web = (WebView) findViewById(R.id.webview);
web.setWebChromeClient(new InternalWebViewClient());
web.getSettings().setJavaScriptEnabled(true);
web.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
web.getSettings().setPluginsEnabled(true);
web.getSettings().setSupportMultipleWindows(true);
web.getSettings().setSupportZoom(true);
web.getSettings().setAppCacheEnabled(true);
web.getSettings().setSaveFormData(true);
web.getSettings().setSavePassword(true);
web.getSettings().setBuiltInZoomControls(true);
web.setHorizontalScrollBarEnabled(true);
web.setVerticalScrollBarEnabled(false);
The site you are trying to load uses self signed certificates. The solution is to ignore certificate checking as described here: Does the Web View on Android support SSL?

Categories

Resources