I am new in android. I am trying to make just a sample application to open websites in webview. The problem is, website opens in desktop mode. How can I open websites just like UCBrowser (mobile mode) ?
Try this. It should work.
webview1.getSettings().setJavaScriptEnabled(true);
webview1.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(getApplicationContext(), description, Toast.LENGTH_SHORT).show();
}
});
webview1.getSettings().setLoadWithOverviewMode(true);
webview1.getSettings().setUseWideViewPort(true);
webview1.getSettings().setBuiltInZoomControls(true);
webview1 .loadUrl("http://www.matrixsystems.net.in/"); // set url
webview1.requestFocus();
Related
I just want to make an make that open ad in my app.
Features:
When interstitial ad show and user clicks on ad then don't show pop up dialog containing browsers to open URL, instead URL must open in same app.
Same must do when banner ad click.
I know i want to use webview but how to open ad click URL in that webview.
If anyone knows how to implement this code then help me.
webSettings.setJavaScriptEnabled(true);
webSettings.setUseWideViewPort(true);
webSettings.setLoadWithOverviewMode(true);
webView.setWebViewClient(new MyWebViewClient());
webView.loadUrl(_URL);
}
private class MyWebViewClient extends WebViewClient{
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
#Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(getApplicationContext(), "Oh no! " + description, Toast.LENGTH_SHORT).show();
}
}
try with this
I'm trying to do a webview based application for this website to show it in a mobile application.
when I put any different site the application work great, but in this specific site never show the second page when I clicked in the button to go to the desk page. However, I put a Log statement in the onPageFinished method and log that the page is loaded completely.
My Code Here
final WebView myWebView = (WebView) rootView.findViewById(R.id.webview);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.setWebViewClient(new WebViewClient() {
#Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(getActivity(), "Oh no! " + description, Toast.LENGTH_SHORT).show();
}
#Override
public void onPageFinished(WebView view, String url) {
Log.d("WEBSITE", "Page Loaded.");
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Log.d("WEBSITE", url);
myWebView.loadUrl(url);
return false;
}
});
myWebView.loadUrl("https://demo.frappecloud.com/");
I believe the problem is with your shouldOverrideUrlLoading. If you check the documentation you will see that :
This method is not called for requests using the POST "method"
When you are submitting the Form, you are making a POST request, which is basically ignored.
Here is the link: WebViewClient
Also check this reference where it says how you could load a URL with POST data: LOAD A POST REQUEST INTO A WEBVIEW IN ANDROID
Consider checking this thread: Android - how to intercept a form POST
I am using an authenticated webview in my app. Currently when we enter the search term in the search box,it is added to the url (say http.cookies.com/something/SEARCHTERM/something) and the url is called in the webview which loads the url as follows:
if(!StringUtils.isEmpty(URL)){
if(URLUtil.isValidUrl(URL)){
mWebview.loadUrl(URL);
}else{
mWebview.loadUrl("http://www.google.com");
}
However, even if the url is invalid, it still loads the invalid url which shows up as "412- precondition set and hence page cannot be displayed".Is there a way I can detect if this search term or url is valid and display it in the webview , if valid) as the requested url , if not valid, i display some other webview like say google.com?
Thanks!
justin
You can use the Webview's WebViewClient to catch the error and do whatever you see convenient. Here is a sample:
yourWebView.setWebViewClient(new WebViewClient() {
#Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
// TODO Auto-generated method stub
super.onReceivedError(view, errorCode, description, failingUrl);
}
});
I'm trying to display web page using WebView in android, when a particular page doesn't load, it displays error message with URL, saying that abcd.com is not available, how do I replace the error message with my custom message instead of displaying the URL?
storeLocator.setWebViewClient(new WebViewClient(){
#Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
storeLocator.loadUrl("file:///assets/error.html");
}
});
storeLocator.loadUrl("http://goog.c");
You can create the html page whatever you want to show whenever the error comes or your page is not available ,the code is given here-
webview.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
webview.loadUrl("file:///android_asset/myerrorpage.html");
}
});
I am using webview to show google canlender but want to pass google account programmatic-ally,so the setHttpAuthUsernamePassword() function should be what I need but it doesn't work at all. Here is the code:
WebView webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.setHttpAuthUsernamePassword("www.google.com", "", "email", "password");
webview.setWebViewClient(new WebViewClient() {
#Override
public void onReceivedHttpAuthRequest (WebView view, HttpAuthHandler handler, String host,String realm){
handler.proceed("email","password");
}
}
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(activity, description, Toast.LENGTH_SHORT).show();
}
});
webview.loadUrl("http://www.google.com/calendar/");
If you have any idea to make this worked, please let me know. I tried to search a lot but don't see any useful.
You're trying to use HTTP authentication (http://en.wikipedia.org/wiki/Basic_access_authentication) which is not supported by most web services. You need to have valid Google cookies, which are set only when you manually sign in with your password.