I'm using standard addresses like google and facebook, but loadUrl does nothing, it just sits there at a white screen, but if i pipe html into it using loadData, it works fine. Any ideas or tips? I've got it enabling javascript, and I have this call:
mWebView.setWebViewClient(new WebViewClient() {
#Override
public void onPageFinished(WebView view, String url) {
TextView t;
t = (TextView)findViewById(R.id.pageTitle);
t.setText(view.getTitle());
}
});
Do i need to override anyhting else?
Check whether you have enabled INTERNET permission in Android manifest file.
Related
I have tested my app with many https URLs, almost all are working fine but not the one I want. I have tested my URL, it's working fine with all the browser except Internet Explorer.
Already handling SSL Error
Override shouldOverrideUrlLoading too.
webView.getSettings().setJavaScriptEnabled(true);
I want to know whether it's the problem in the URL or from Android.
I have solved my problem by enabling DomStorage.
webview.getSettings().setDomStorageEnabled(true);
I have searched about domStorage, as i understand it works if website using HTML5. Don't know too much about dom storage.
Just try to ignore SSL, check below snippet.
webView.setWebViewClient(webViewClient);
private WebViewClient webViewClient = new WebViewClient() {
#Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
handler.proceed(); // Ignore SSL certificate errors
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
}
};
Did you enable javascript on the webview?
webView.getSettings().setJavaScriptEnabled(true);
Most probably, its the problem in the URL not with the Android. As you are saying there is no SSL certificate issue and all other https URL's are working except yours.
You should contact your service provider or check from web end.
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.
I've developed a small group of .html pages that are stored in a server.
My android app, using a webview with: setWebChromeClient loads these pages.
minSdkVersion 19
targetSdkVersion 24
The problem:
Everytime I need to load a new page, using a link in my .html page, the new page is opened in an external browser.
Url Overriding
I know about the shouldOverrideUrlLoading() method, when we're using the setWebViewClient().
But unfortunately I can't use the normal webview. I need to use the WebChromeClient() because of some feature that only work with this one. (Like the input file)
My doubt is...
How can I override my URL to force them to load inside of the webChromeClient?
I tried this but with no luck:
webView.setWebChromeClient(new WebChromeClient() {
// (...)
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
You can use following code to achieve this.
WebView web = (WebView)findViewById(R.id.web);
WebSettings webSettings = web.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setSupportMultipleWindows(true); // This forces ChromeClient enabled.
web.setWebChromeClient(new WebChromeClient(){
#Override
public void onReceivedTitle(WebView view, String title) {
getWindow().setTitle(title); //Set Activity tile to page title.
}
});
web.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
});
I was using an embedded mobile web application in an Android App making use of the WebChromeClient class and did not want to fiddle around with recompiling the APK.
While looking for the easiest header(); solution (since the mobile web application is in php) I found out that using:
header("Location: url.php", TRUE, 307);
was a quick fix solution without recompiling the Android app.
This allowed the user to re-direct within the app without calling the web browser externally from my app.
Here is the link to the answer by Arindam Nayak where I got the idea from.
I am working on one Android App where I am loading local file contents into webview using following syntax.
url = "file://" + mLocalFilePath + java.io.File.separator + CURRENT_FILE;
webView.loadUrl(url);
The issue is the webview loads file contents and also loads the various images from url present in webpage ( webpage has many images ).
The challenge I am facing is I want to get notified when webview finish rendering entire html page.I want to get notified when webpage is 100% loaded.
I reffered various forums and also tried using
window.onload function
as well as
public void onPageFinished(WebView view, String url)
But I did not get desire output,I get callback before html page is completely loaded.I am looking for way so that I will get notified only when webpage has finished rendering all the images present in web page.( i.e Webpage is 100% loaded.)
I am not looking for complete answer even hints will be appreciated.
Thanks
Try this way
webView.setWebChromeClient(new WebChromeClient(){
#Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
if(newProgress==100){
// page loading completes
}
}
});
I used deprecated PictureListener that start when all images on the pages are loaded. It deprecated and you need at least one image in the html but if you can manage this (you could place transparent 1px*1px image) it's a good solution.
wv.setPictureListener(new PictureListener() {
#Override
public void onNewPicture(WebView view, Picture picture) {
// some code here
}
}
});
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);
}
});