Browsing a site using webView in ANdroid - android

I have loaded a website with my WebView. But when I click in any link of that website , the control has been transferred from my WebView to the Android built in browser. I want to browse that site with my WebView.
I want to download book from my site. Another task that is very important to me is when I will download a book from my site ,it will give a password to my software ( android part ). What do I do to receive a password from an web site from the WebView.
This question is very important for me to complete my project.
Waiting for your replies...
The code for webView is just as following:
wv = (WebView) findViewById(R.id.mainwebview);
WebSettings ws = wv.getSettings();
ws.setBuiltInZoomControls(true);
wv.loadUrl("http://m.feedbooks.com/store");
wv.getSettings().setJavaScriptEnabled(true);

wv.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view,String url) {
view.loadUrl(url);
return true;
}
});
wv.loadUrl(url);
above code can help you to display website with your webview

Have a look at the WebViewClient1
You can override shouldOverrideUrlLoading(WebView view, String url)

Related

Android webview tel:0000 could not be loaded because net:ERR

I am building an android application. I am showing external webpage in webview. I have followed these steps:
Load external website in webview. For example example.com, it loads fine in webview
There is an option in example.com site to launch Dialer app on button click. Here is the code.
<div class="center">
<input type="image" src="btn.png" onclick="location.href='tel:0000';"/>
</div>
When I go to example.com from mobile browser and click on button, it can launch Dialer app with phone number
When I click from webview it shows this error
Web page not available
The web page at tel:0000 could not be loaded because:
net::ERR_UNKNOWN_URL_SCHEME
I do not know what is went wrong. Any clue will be helpfull.
NB: I am using real phone number (here it is 0000).
Thank you
You should set a WebViewClient to the WebView and than override shouldOverrideUrlLoading method as follow:
myWebView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
if (request.getUrl().toString().startsWith("tel:")) {
Intent intent = new Intent(Intent.ACTION_DIAL, request.getUrl());
view.getContext().startActivity(intent);
}
return super.shouldOverrideUrlLoading(view, request);
}
});

View website inside a webview with custom CSS

I am looking for a way to load custom css into a website inside my app. Kinda like how stylish works in chrome, but then loading the css from the assets or my own website.
The website that I want to style has a horrible layout and it doesn't work at all on mobile, this is why I want to change it.
I have looked all over the internet for a solution for this problem. I came accross this solution. But that doesn't seem to work for me.
This is my current code inside OnCreate:
final String url = "http://sub.domain.com/";
final WebView browser =(WebView) this.findViewById(R.id.browser);
browser.getSettings().setJavaScriptEnabled(true);
browser.setWebContentsDebuggingEnabled(true);
String htmlData;
htmlData = "<link rel=\"stylesheet\" type=\"text/css\" href=\"Style.css\" />";
browser.loadDataWithBaseURL("http://www.example.com/folder/", htmlData, "text/html", "UTF-8", null);
browser.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
browser.loadUrl(url);
return false;
}
});
I have checked element inspect in chrome, and there it displayed an about:blank with a link in the header to my custom styling. So how do I get it to display my custom styling?

WebView fails to render certain webpages

I'm trying to show 2 webpages in WebViews. The 1st one works fine, but the 2nd will result in a blank screen.
This happens on Android 4.2.2, if I run this on a Lollipop it works fine. Moreover, I tried saving the page to the assets folder in my project and it could load properly that way.
Here are the URLs I am trying to load:
1. http://www.taiwanjobs.gov.tw/mobileApp/docDetail_frame.aspx?uid=411&pid=221&docid=141
2. http://www.taiwanjobs.gov.tw/mobileApp/docList_frame.aspx?uid=412&pid=221
Here is my code:
final WebView webView = (WebView) getView().findViewById(R.id.webview);
webView.setWebViewClient(new WebViewClient());
webView.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setDisplayZoomControls(false);
webView.loadUrl(url);
Please help me. Thanks!
You should try this code...
I think you have to override the urlloading as below code...
webView = (WebView) view.findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new webViewClient());
webView.loadUrl(url);
private class webViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
So... turns out the issue was from the webpage itself,
WebView in Android 4.2.2 just wasn't supporting it,
I tried opening it with the web browser on an Android 4.2.2 emulator,
same results.

Android loadUrl unable to load site

My webview will works for a site such as Google.com, however, the specific page will not load.
Simply displays subscribe to feedburner (I made this site to reflect a converted news feed)
This specific webpage will display correctly in an Iphone UIWebView, but not for Android.
Some code
WebView rss = (WebView) findViewById(R.id.webviewRSS);
rss.loadUrl("www.newmanu.edu/newmannews");
Check out the source of "www.newmanu.edu/newmannews", you have to activate javascript.
from http://developer.android.com/guide/webapps/webview.html
WebView myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
Add http:// or https:// before URL.
Try this.
rss.loadUrl("http://www.newmanu.edu/newmannews");
Or
rss.loadUrl("https://www.newmanu.edu/newmannews");

Can't type inside a WebView

I have a problem interacting with a WebView. I'm showing an HTML login form within a WebView and I can't type inside of any of the input fields of the forms. I do can interact with the links, select boxes, buttons, etc.
Here is an example of my code. Basically I'm retrieving the web view from the xml and setting it a WebViewClient and a WebChromeClient.
webview = (WebView) findViewById(R.id.loginWebview);
webview.getSettings().setJavaScriptEnabled(true);
WebViewClient client = new WebViewClient();
webview.setWebViewClient(client);
webview.setWebChromeClient(new WebChromeClient());
webview.loadUrl("http://www.google.com");
Any ideas?
You can do the following to solve this:
WebView webView = (WebView)findViewById(R.id.yourWebView);
webView.getSettings().setJavaScriptEnabled(true);
webView.requestFocus(View.FOCUS_DOWN);
There is another post here.

Categories

Resources