I created a WebView (with JavaScript enabled) in my app to display a link programmatically. I send the url to it, and it loads. I do the same thing, instead sending it programmatically to a browser on the phone.
These look like the first picture.
The problem is the page displayed in both of these cases is different than if I copy and paste the link (generated in the app from the Log) to the same browser on the device manually, or open it on my desktop browser. These look like second picture.
A sample link is:
http://lyrics.wikia.com/index.php?title=Future:Karate+Chop+%28Remix%29&action=edit
Why could this be?
Sounds like you need to override the shouldOverrideUrlLoading in your WebViewClient, which should be attached to your webview, also in the overriden method it should return false if you want your webview to handle it.
The second thing I would recommend would be to also change the UserAgent that is being attached to your WebVIew as well since you're seeing a difference in Desktop/Mobile version of the website.
You can learn more about tweaking the user agent here:
Want to load desktop version in my webview using uastring
Related
I have a CodeName One app where I'm using the BrowserComponent to load an HTML page. This HTML page (HTMLPage1) further opens another HTML page (HTMLPage2) on the click of a button using window.open(). This works correctly in the app. This HTMLPage2 has a Close button and on clicking this button, HTMLPage2 should be closed and the control should go back to HTMLPage1. However, this is not working as expected. On clicking the Close button, nothing happens in the app and HTMLPage2 is still shown in the app. I have tried using window.close() and self.close() and neither of them work.
I found the following article on searching
Android Webview: Scripts may close only the windows that were opened by it that seems similar to the problem I am facing
Also, I have a WebView Test app (can be found on PlayStore - search for com.snc.test.WebView Test) on my mobile that lets me modify the WebView settings and launch different URL's. I used this app to check if I can successfully invoke my HTML pages through the WebView Test app. With the default settings, I ran into the same problem as described above. The Close button didn't work.
However, then I modified the setSupportMultipleWindows() property in the app and set it to true. After that, it worked correctly through the WebView Test app. On clicking Close in HTMLPage2, that page was closed and I could see HTMLPage1 again.
So, I tried checking how to set this property in CodeName One. I found that the BrowserComponent.setProperty("SupportMultipleWindows", "true") should be able to do the same thing. When I set this property and tested the app, it still didn't work.
Then I looked through the documentation of
WebSettings.setSupportMultipleWindows
According to this documentation, if set to true, WebChromeClient.onCreateWindow(WebView, boolean, boolean, Message) must be implemented by the host application.
I could not find a way to do this through CodeName One.
Am I going down the right path to tackle this problem? If not, kindly guide me.
I'm new to android. I have a question related to WebView.
It's not clear to me how WebView works.
When we use a WebView, does the mobile start a new browser in order to load
the URL (even if the url is online or locally stored on the mobile)?
Cause, I would like to create a native android app (test.apk) with WebView
and its's not clear to me if the app starts from the browser or from
an inline View.
Any tutorial or example would be very helpful
Thanks
A WebView is a view that displays web content right inside your app. It does not have fancy stuff like bookmarks or a history view, but you could build a full featured browser around a WebView. Imagine a WebView as a view that displays a web page.
If you want to start an external web browser app, you can use an Intent to let the system find a suitable app to handle your url.
Webview is :
View that displays web pages.
Provides no browser-like widgets, does not enable JavaScript
Uses WebKit rendering engine to display web pages and includes methods to navigate forward and backward through a history, zoom in and out.
Check Android Webview for detailed information.
I have a code in my application to open a browser.
Sometimes I need to tell the browser to load another URL after a few seconds.
Is there a way to make the first browser to change the URL or I need to open a new one always?
Thanks,
Simon
The best way to achieve this would probably be to embed a WebView in your application, and then you can control it directly. Otherwise, as far as I know, you can't control a browser opened up via Intents. I could be wrong about that, but embedding a WebView and controlling it directly seems much more straightforward.
The WebView class reference:
http://developer.android.com/reference/android/webkit/WebView.html
Some notes on the WebView (less pertinent to what you're doing [this article pertains to writing HTML/native hybrid apps], but may have some useful information):
http://developer.android.com/guide/webapps/webview.html
I built a very simple web page for online FAQ reference.
This is basically a plain html page with very few css.
When I open it form my PC brawser it looks just fine, also when I open it from different smartphones (in default brawser) it looks cool in all of them.
Now my problems rises when I try to open it inside my mobile app by calling an intent with ACTION_VIEW like this:
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://my.domain.it:8443/FAQ/")));
In fact this leads to different behaviours depending on the device used to perform this action. Samsung S2 displays it right, but most of the other devices (i.e. Samsung Note, all Galaxys...) display the site much more zoomed than in ordinary brawser's view, also the zoom seems to be somehow 'fixed' as even zooming out the view won't turn it to the regular brawser correct view.
Is there something I can do for this? I've been googling this for a while but couldn't find a single helpful link.
EDIT
I validated the HTML and the CSS with an online validator and it gives "Valid" in both.
Thanks.
Check your site for HTML or CSS errors. Your issue got nothing in common with android really, but the way 3rd party application interpret your HTML/CSS
I have a string which consumes the html code of a form and I want to show that form in my app and it should also work further as on submit it should move forward to next page.
I used WebView, it just shows the page in a static way. It don't support buttons and DatePicker, so I DONT WANT WEBVIEW.
First off, WebView does support buttons, and you could support a DatePicker either by using an HTML/JS one or by doing something fancy to route a request to the Java side of things. I really suspect your insistence on not using WebView is going to prove unproductive.
That said, sure you should show your HTML in your app without using WebView... you could write your own web control or take another (Firefox is open source as is WebKit on which WebView is based, in fact so is WebView itself for that matter). That's going to be a heck of a lot of work though.