I need to post data to Webview.
I found from some of the links the below code:
WebView webview = new WebView(this); setContentView(webview); String url = "http://www.example.com"; String postData = username=my_username&password=my_password"; webview.postUrl(url",EncodingUtils.getBytes(postData, "BASE64"));
But in my android studio I see EncodingUtils as deprecated
Can anyone help me what is the alternative for EncodingUtils to post data to Android WebView?
webView. setWebViewClient(new WebViewClient(){ public void onPageStarted(WebView view, String url, Bitmap favicon) { super. onPageStarted(view, url, favicon); } public boolean shouldOverrideUrlLoading(WebView view, String url) { webView. postUrl(Base_Url, postData.
This interface was deprecated in API level 12. This interface is now obsolete.
loadUrl when you say loadUrl. From documentation, only difference between them is, loadURL renders a webkit having a url that you set. On the other hand, loadData renders webkit, that source code comes from a parameter, and baseURL is also a parameter.
Try like below...
Java:
WebView webview = new WebView(this); setContentView(webview); String url = "http://www.example.com"; String postData = "username=" + URLEncoder.encode(my_username, "UTF-8") + "&password=" + URLEncoder.encode(my_password, "UTF-8"); webview.postUrl(url,postData.getBytes());
Kotlin:
val webview = WebView(this) setContentView(webview) val url = "http://www.example.com" val postData = "username=${URLEncoder.encode(my_username, "UTF-8")}" + "&password=${URLEncoder.encode(my_password, "UTF-8")}" webview.postUrl(url, postData.toByteArray())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With