I am using a webview to submit a form and redirect. When the form is submitted successfully it will print a json response to the console.
My question is how can I get the jsonData String from the client?
chromium: [INFO:CONSOLE(1)] "Callback....jsonData, etc"
webView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// Insert your code here
return true;
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
}
});
You could extend the WebViewClient class and create a method to intercept the POST request made from clicking the form post button in the HTML in your WebView. Then, make the HTTP POST request in the code, rather than in the WebView and parse the results anyway you wish, then refresh the WebView any way you wish at the end of it all. There is an example of doing so here:
https://github.com/KeejOow/android-post-webview/blob/master/PostWebview/postwebview/src/main/java/com/solidsoftware/postwebview/InterceptingWebViewClient.java
Related
My WebView converts https to http, as evident from checking the url parameter in shouldOverrideUrlLoading() method.
I have tried using
webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE), but it doesn't work.
How do I fix this?
Please help!
you can handle every url as you wish just set up your webview via customized WebViewClient
webview.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView webView, String url) {
if (url.startWith("https")) {
//do whatever you need
}
return false;
}else if(....
I have a specific url to load in web view, but it's redirecting me to the login page due to the cookies . The web login page uses the same username, password credential I use for my native login . So how can I set the cookies using the username, password I have so it won't redirect me to login page?
Currently I am sending the username, password with post data and after finishing I am loading the required url in another web view. But it's taking too long to load as it's loading to web view one after another.
String postData = "username="+userName+"&password="+password;
webView.postUrl("logipage url", EncodingUtils.getBytes(postData, "base64"));
webView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
#Override
public void onPageFinished(WebView view, String url) {
webView2.loadUrl("Main URL");
}
});
I have a webview in my Fragment. An HTML string is loaded to it. The string contains the link tag: "anyText"
Then I set a webviewclient for my webview.
webview.setWebViewClient(new WebViewClient() {
// you tell the webclient you want to catch when a url is about to load
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url){
Logger.d("url="+url);
return true;
}
// here you execute an action when the URL you want is about to load
#Override
public void onLoadResource(WebView view, String url){
Logger.d("url="+url);
}
});
My issue is that if click on the link, my WebViewClient cannot catch it.
But if I change it to "anyText", then it will work cos the href value is a valid link.
What I wanted to achieve to is put any href value and catch it. I am also NOT visiting any site here. Just want to catch that anyText and do something else.
String url="https://www.google.com"
Did u give Network permission in android manifest?
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 have a webview containing a form which has both send and cancel buttons. The webview opens in a dialog and I'd like this to close upon either successful form submission or cancellation. The buttons are part of the webview's HTML. The form exists on a third party server that I have no control over. The send button reloads the parent page, and the cancel button closes the form on the originating site. I'm using an HTML parser to display just the form and buttons.
Is there a way to accomplish this?
This worked for me
/**
* Custom web client to let us override behaviour when the edit form has been submitted
*/
private WebViewClient getWebviewClient() {
return new WebViewClient() {
/**
* let's finish this activity once the form has been saved and a message has been display
*/
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
if (url.contains(DONE_URL)) {
displayDialogToFinishActivity();
}
}
};
}
WebViewClient rclient = new WebViewClient(){
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url){
return true;
}
#Override
public void onLoadResource(WebView view, String url){
finish();
}
};
webview.setWebViewClient(rclient);
This seems to work.