I want to show a bank website application for paying online .I should use webview , this is my webview code :
WebView wb = (WebView) findViewById(R.id.webView1);
WebSettings settings = wb.getSettings();
settings.setDefaultTextEncodingName("utf-8");
settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
settings.setSupportZoom(true);
settings.setJavaScriptEnabled(true);
settings.setSaveFormData(false);
settings.setSavePassword(false);
settings.setDomStorageEnabled(true);
progressBar = ProgressDialog.show(Pay.this, Z_Farsi.Convert(getString(R.string.gettingdata)), Z_Farsi.Convert(getString(R.string.wait)));
wb.setWebViewClient(new WebViewClient() {
#Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
handler.proceed();
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
public void onPageFinished(WebView view, String url) {
if (progressBar.isShowing()) {
progressBar.dismiss();
}
}
});
The problem is , it's going to a step that I need to click on a button to connect to paying web page . I don't know why it doesn't work and button doesn't press down .
I tested it on android default browser and it worked fine .
Could you help me ? Why does that button is not working on webview?
Related
I have a webview that display the google page and i want to do something when the search button in the google page is pressed is it possible ?
here is my webview :
WebView wb=(WebView) findViewById(R.id.webView);
wb.getSettings().setJavaScriptEnabled(true);
wb.getSettings().setLoadsImagesAutomatically(true);
wb.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
wb.loadUrl("https://www.google.com");
You can use WebViewClient to listen for url changes. It doesn't exactly allow to listen for that specific button, but you can just check the url, like so:
WebView wv = (WebView) findViewById(R.id.webView);
WebSettings ws = wv.getSettings();
ws.setJavaScriptEnabled(true);
WebViewClient wvc = new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
boolean isSearch = url.startsWith("https://www.google.com/search");
if (isSearch) {
Log.d("WebView", "search clicked");
return true;
}
return false;
}
};
wv.setWebViewClient(wvc);
wv.loadUrl("https://www.google.com");
I know this is late, but yes you can. You have to set up a JavaScript event listener as a url query to load on Android's side.
..
webView.addJavascriptInterface(new JSInterface(), "SearchClicked");
webView.setWebViewClient(new WebViewClient() {
#Override
public void onPageFinished(WebView view, String url) {
String query =
"document.getElementsByClassName('BwoPOe').item(0).addEventListener('click',
function() {SearchClicked.doTasks()}, false);";
webView.loadUrl("javascript:" + query);
}
});
webView.loadUrl("https://images.google.com/");
..
Here when loading the WebView, you're getting the Google search button by getting a class name called BwoPOe, and setting it's event listener to call the JSInterface method doTasks.
You can find out the button class name using the Chrome's inspect element tool.
private class JSInterface {
#JavascriptInterface
public void boundMethod(String html) {
// do something...
}
}
https://mobilogr.uludag.edu.tr/Login.aspx
I can't open this website in Android webview
WebSettings settings = mWebView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setUseWideViewPort(true);
settings.setSupportMultipleWindows(true);
settings.setAllowFileAccess(true);
mProgressDialog = ProgressDialog.show(this, "Uygulama Yükleniyor",
"...yükleniyor...");
mWebView.setWebViewClient(new WebViewClient() {
mWebView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
public void onPageFinished(WebView view, String url) {
if (mProgressDialog.isShowing()) {
mProgressDialog.dismiss();
}
}
});
mWebView.loadUrl("https://mobilogr.uludag.edu.tr/Login.aspx");
Please check whether your android Android Manifest for the Internet Permission as shown below
<uses-permission android:name="android.permission.INTERNET" />
Does your application have the permission to go on the internet?
<uses-permission android:name="android.permission.INTERNET" />
also, you want to go to this website,
but your url in your script goes to another?
I have faced the similar issue.
The easiest way is to debug and see, the page may have a broken javascript.
You need to remote debug which give you clear error in console.
Try this : https://developer.chrome.com/devtools/docs/remote-debugging
something is wrong with the certificate.
if your ssl Certificate expired or not trusted,webview will refuse to load the webpage.
To avoid this ,you should override onReceivedSslError method like this:
mWebView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
#Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
// super.onReceivedSslError(view, handler, error);
// ignore ssl error
handler.proceed();
}
});
i try this,everything is OK.
I'm using a webview:
WebView webview = new WebView(this);
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setLoadWithOverviewMode(true);
webview.getSettings().setUseWideViewPort(true);
webview.getSettings().setGeolocationEnabled(true);
webview.setWebViewClient(new WebViewClient(){
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
loading.show();
view.loadUrl(url);
return true;
}
#Override
public void onPageFinished(WebView view, final String url) {
loading.dismiss();
super.onPageFinished(view, url);
}
});
For most links, it works just fine. But for, http://m.stubhub.com (and any of the same domain), it only shows a blank view (though it's finished loading the page). Are there settings, I'm missing or something?
Btw, there aren't any errors, as far as I can tell.
Suggestions/advice greatly appreciated. Thanks.
Did you tried onReceivedSslError ? :
public void onReceivedSslError (WebView view, SslErrorHandler handler, SslError error) {
handler.proceed() ;
}
Let me know if that helps !
The solution was the permissions the site required. It uses HTML5 storage, so permission for DOMStorage had to be enabled...
webView.getSettings().setDomStorageEnabled(true);
I am trying to Load a webview in Android. Where web page have a swf file but it is not loading. I know there are many question and answer on same topic but no one helped me.
I have already targeted it version 11. And I have put android:hardwareAccelerated="true" too in manifest.xml file.
My code is here-
public class MainActivity extends Activity {
private WebView mWebView;
String url="http://mypages.com/Ch_001/ScoPage.html";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView = (WebView) findViewById(R.id.webView);
mWebView.setKeepScreenOn(true);
WebSettings settings = mWebView.getSettings();
settings.setPluginState(PluginState.ON);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setDomStorageEnabled(true);
mWebView.getSettings().setBuiltInZoomControls(true);
mWebView.setInitialScale(100);
// wbView.getSettings().setUseWideViewPort(true);
mWebView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
mWebView.setWebViewClient(new MyWebViewClient());
}
private class MyWebViewClient extends WebViewClient {
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
}
#Override
public void onReceivedSslError(WebView view, SslErrorHandler handler,
SslError error) {
Log.e("Error VAGARO", error.toString());
handler.proceed();
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
}
}
After one week struggle I got a Flash player from Macromedia, which works for me.
You can search in Google for-"Flash Player 11.1.for Android 4.0 - Macromedia - Adobe" or install APK from this link.
Install this apk in your Android device.
And when you will open it, it will ask for choose default browser.
Choose any browser which support Flash (UC-Browser, Chrome etc).
Now run your any application it will load your Flash video.
Add this code:
webview.getSettings().setPluginsEnabled(true);
add mWebView.loadUrl(url);in onCreate
There is a WebView which loads mobile-optimized URL (webpage). But when I click on a link, it does not load inside of the WebView (inside of the app), but mobile browser opens.
How to prevent this?
I tried overloading URLs via shouldOverrideUrlLoading(), but it did not help.
This is a code.
webView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = webView.getSettings();
webSettings.setPluginsEnabled(true);
if (Build.VERSION.SDK_INT > 7) {
webSettings.setPluginState(WebSettings.PluginState.ON);
}
webSettings.setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.equals(url)) {
view.loadUrl(url);
return true;
}
return false;
}
#Override
public void onLoadResource(WebView view, String url) {
}
});
webView.loadUrl("http://some-url.com");
EDIT
Does GET or POST posting methods have anything with links' clicks open mobile web browser???
Return true instead of false in shouldOverrideUrlLoading.
From the documentation:
shouldOverrideUrlLoading returns True if the host application wants to
leave the current WebView and handle the url itself, otherwise return
false.