An alternative to Android's webview - android

Does anyone knows an alternative to Android's webview component ? For some reasons, it's functionality's are insufficient for me : I need to be able to catch every single request to some url, when i'm browsing a wml page (wap). Anyway, I need to be able to do stuff that Android's webview is not made for.
I thought "hey, let's play with the source code, I'm pretty sure that webviews are using apache.org librairies to access internet".
Oh boy was I mistaken. Webviews use native code, and that's where I'm stuck.
So I was wondering if anyone knew of another web browser view, in pure java, that would be open source and nice. It's not a problem if it's slow, i'm displaying some basic wap pages...
Thanks in advance.

You can extend WebView's functionality by using setWebViewClient & setWebChromeClient.
WebView.setWebViewClient(new MyWebViewClient());
WebView.setWebChromeClient(new WebChromeClient() {..}
You can handle each and every request sent/received from the WebView by overriding the below methods:
public boolean shouldOverrideUrlLoading(WebView view, String url) {..}
public void onPageStarted(WebView view, String url, Bitmap favicon) {..}
public void onPageFinished(WebView view, String url) {..}

The crosswalk project: https://crosswalk-project.org/ might be what you need. But beware, there are places where it differs from the stock webview. In some ways better, in some ways worse. For example, it supports WebGL (good), but currently the background cannot be transparent (bad). The really good news, it seems to be very actively supported, running it's own Jira to track and fix and Intel seems to be very involved.

Try to see how was Opera Mini programmed.
But I think you must program it if you want another one . But i would be surprised if it has a nice performance.

Try this:
goButton4.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
Uri uri = Uri.parse("http://tory.com/");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
});

Related

how to show only specific part of website in android webview

I wish to show only the login-page element of a URL. My current approach which is not working:
web.setWebViewClient(new WebViewClient() {
#Override
public void onPageFinished(WebView view, String url)
{
view.loadUrl("javascript:document.getElementByClassName('login-page')");
}
});
web.loadUrl("https://www.reddit.com/reddits/login");
For mobile screens you should develop separate screens and embed it.
Another way is if your web page supports p/# tag (i.e) like
https://developer.android.com/guide/components/fundamentals.html#Components
https://www.reddit.com/reddits#login this should navigate the page directly to login form
Anyhow I prefer you should develop the page for mobile screens.
Your approach is close to working, but you should modify the existing page instead of trying to load a subset of the existing page as a new one.
The following hides elements with class SectionToRemove, you could instead hide all and only make visible the area you need:
#Override
public void onPageFinished(final WebView view, String url) {
super.onPageFinished(view, url);
view.loadUrl("javascript:$('.SectionToRemove').hide();");
}
That being said, Reddit has extensive APIs that should be used if possible, this approach may breach Terms of Service.

Is shouldOverrideUrlLoading called for links within the same domain?

I have a hybrid application where I have a WebView which is implementing the shouldOverrideUrlLoading method (both the deprecated and the newest version). This should take over control before loading any external links or certain links within my domain. Without going into specifics, the code looks roughtly like this:
private WebView mWebView;
mWebView.setWebViewClient(new myWebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(url.isExternal() || url.contains("#specialCase")) {
// Do actions
return true;
}
return super.shouldOverrideUrlLoading(view, url);
}
});
I have noticed that all external links work properly, however shouldOverrideUrlLoading is not being called at all when the link is within my domain, so there is no way for me to detect those cases where I want to take over control.
The android documentation states
Give the host application a chance to take over the control when a new
url is about to be loaded in the current WebView.
Does that new mean different domain? Is there anything I am missing or doing wrong? Any ideas on how to detect the user has clicked a link pointing to the same domain?
Thank you in advance.
Finally found the reason why shouldOverrideUrlLoading was never been called.
Apparently the method is only called when the actual loading is about to start. Our web application is a single-page application, hence even though the URL changes, no new page is loaded and shouldOverrideUrlLoading is not called.

Open URL with custom BROWSER

Good day!
Guys, I have a problem and want your help.
Through a WebView, how do I get when clicked by the user, do not open the options of standard browsers (eg chrome and internet). I saw an app by clicking the link to the page opens normally however, as if open in a custom browser. I found it very interesting, and I wonder how this mechanics.
If anyone know how to create an app that perform the same procedure I am grateful.
For better doubt the APP is this:
https://play.google.com/store/apps/details?id=com.tachanfil.jornaisdobrasil&hl=pt-BR
You have to set up WebViewClient like
this.mWebView.setWebViewClient(new WebViewClient(){
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url){
view.loadUrl(url);
return true;
}
});
Then your app will display all links in your WebView instead of opening browser
Perhaps you are missing setting your client as the webview client - Refer to
http://developer.android.com/reference/android/webkit/WebView.html#setWebViewClient%28android.webkit.WebViewClient%29

Prevent Android WebView caching data

Is it possible to prevent a WebView from caching data in /data/data/???/cache/webViewCache? I've set the following on the WebSettings but the cache folder is still used:
webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
webSettings.setAppCacheEnabled(false);
I've noticed that the cache files are deleted on application exit or when the application goes into the background but I'd prefer for them not to be created at all. Furthermore I'd like to prevent the use of the webview.db & webviewCache.db found in /data/data/???/database. I currently delete the databases like so:
context.deleteDatabase("webview.db");
context.deleteDatabase("webviewCache.db");
This appears to have the desired effect and the files don't appear to be recreated again for use. Is it safe to assume this is the case?
The notes on this page lead me to believe they don't want you to have fine access to the cache:
http://developer.android.com/reference/android/webkit/CacheManager.html
As far as I can tell, there are (at least) two ways around keeping cache. I haven't written any of this in an app, so no guarantees:
(1) Every time your WebView finishes a page, clear the cache. Something like this in your WebViewClient:
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
view.clearCache(true);
}
(2) If you don't care too much what is stored, but just want the latest content, you might be able to achieve this by setting the right http headers on loadUrl (obviously you'd want to test this against your server). Also, this is only available for Android API 8+
Map<String, String> noCacheHeaders = new HashMap<String, String>(2);
noCacheHeaders.put("Pragma", "no-cache");
noCacheHeaders.put("Cache-Control", "no-cache");
view.loadUrl(url, noCacheHeaders);
Maybe you tried this, but maybe also set the WebView Cache size to something small. I'm not sure if 0 will work, so maybe 1:
wv.getSettings().setAppCacheMaxSize(1);
Good Luck!
In my application (on Android 4.2.2) I load on a webview a web page with images that I can change at runtime (I replace the images while keeping the path). The Matt's solution (1)
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
view.clearCache(true);
}
works for me, the solution (2) no!
Cheers

Keeping a webView contained in Android?

Hey everyone! Im pretty new to Android and I have a webView under 2 other widgets on the screen(Or w/e you call it). But when ever I navigate the webView, its changes to full screen and i cant see my other widgets. Ive looked all over Google but couldn't find anything, is there some way I can fix this?
Im using this code to navigate:
webView.loadUrl("http://www.example.com/");
Thank you.
webview.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url){
view.loadUrl(url);
return true;
}
});
when you do webView.loadUrl("www.example.com") or if there is a redirection when a hyperlink is clicked or something similar, the android device browser is started. I believe you are stuck with this. Try pasting the above code before you call the webView.loadUrl("www.example.com")
What we are essentially doing is asking the webview to load the url, instead of opening it in the device browser.

Categories

Resources