I am working with xWalkWebView
and I would like to know the equivalent to this code
webView.setWebViewClient(new WebViewClient() {
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
// progressBar.setVisibility(View.VISIBLE);
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
// progressBar.setVisibility(View.GONE);
}
#Override
public void onReceivedHttpAuthRequest(WebView view,
HttpAuthHandler handler, String host, String realm) {
}
});
Thanks using Crosswalk, you can also ask question by sending email to
crosswalk-help#lists.crosswalk-project.org
For this question:
mXWalkView.setUIClient(new XWalkUIClient(mXWalkView) {
#Override
public void onPageLoadStarted(XWalkView view, String url) {
System.out.println("onPageLoadStarted " +url);
}
#Override
public void onPageLoadStopped(XWalkView view, String url,
LoadStatus status) {
System.out.println("onPageLoadStopped " + status);
}
});
mXWalkView.setResourceClient(new XWalkResourceClient(mXWalkView) {
#Override
public void onReceivedHttpAuthRequest(XWalkView view,
XWalkHttpAuthHandler handler, String host, String realm) {
System.out.println("onReceivedHttpAuthRequest");
}
});
Related
i am trying load a .php file in WebView. it was working properly before API level 28 after i updated to API level 28 its not working its showing white screen. nothing is showing i tried all the options.
Here is the code
I am added the safe browsing false in the manifest file also.
I tried searching in the google nothing is helped me if any one done please help in this case to resolve.
String url="https://xxx/xxx/abc.php";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
handleSSLHandshake();
WebView mWebView = (WebView) findViewById(R.id.webView);
// PackageInfo webViewPackageInfo = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// webViewPackageInfo = WebView.getCurrentWebViewPackage();
mWebView.getSettings().setSafeBrowsingEnabled(false);
// Log.d("MY_APP_TAG", "WebView version: " + webViewPackageInfo.versionName);
}
WebViewClientImpl webViewClient = new WebViewClientImpl(this);
mWebView.setWebViewClient(webViewClient);
mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
mWebView.getSettings().setBuiltInZoomControls(false);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl(url);
if (18 < Build.VERSION.SDK_INT ){
//18 = JellyBean MR2, KITKAT=19
mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
}
}
public class WebViewClientImpl extends WebViewClient {
private Activity activity = null;
public WebViewClientImpl(Activity activity) {
this.activity = activity;
}
#Override
public boolean shouldOverrideUrlLoading(WebView webView, String url) {
webView.loadUrl(url);
// Log.i(TAG,url);
return true;
}
#Override
public void onLoadResource(WebView view, String url) {
super.onLoadResource(view, url);
}
#Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
}
#Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
}
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
#Override
public void onPageFinished(WebView view, String url) {
}
}
I solved my problem. it was the certificates issues, i just added the following code, its working fine now
#TargetApi(Build.VERSION_CODES.N)
#Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
view.loadUrl(request.getUrl().toString());
return true;
}
#Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
handler.proceed();
}
I'm getting the URL and finishing the activity when the URL is stackoverflow.com. How do I pass this URL to Parent Activity?
wvPayment.setWebViewClient(new WebViewClient(){
#Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
Log.d(TAG, "shouldOverrideUrlLoading: "+String.valueOf(request.getUrl()));
if(String.valueOf(request.getUrl()).equals("http://stackoverflow.com/")){
finish();
Toast.makeText(PaymentActivity.this ,"Successful",Toast.LENGTH_LONG).show();
}
return true;
}
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
wvPayment.setVisibility(View.GONE);
ProgressBar.setVisibility(View.VISIBLE);
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
wvPayment.setVisibility(View.VISIBLE);
ProgressBar.setVisibility(View.GONE);
}
});
The following code is the MainActivity of the app. I tried to add a Custom Error page by using:
mywebView.setWebViewClient(new WebViewClient() {
#Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
mywebView.loadUrl("file:///android_asset/error.html");
} });
When I use the above code in the main activity either the Error page or the Loading Icon are working at a time. (overriding each other).
I'm not understanding where I'm mistaking. Can anyone please help me fix this problem? Thanks in advance.
public class MainActivity extends AppCompatActivity {
public WebView mywebView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mywebView = (WebView)findViewById(R.id.webView);
WebSettings webSettings = mywebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mywebView.loadUrl("http://google.com/");
mywebView.setWebViewClient(new WebViewClient());
mywebView.setDownloadListener(new DownloadListener() {
public void onDownloadStart(String url, String userAgent,
String contentDisposition, String mimetype,
long contentLength) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
}
});
mywebView.setWebViewClient(new WebViewClient() {
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
findViewById(R.id.progress).setVisibility(View.VISIBLE);
}
public void onPageFinished(WebView view, String url) {
findViewById(R.id.progress).setVisibility(View.GONE);
}
});
}
public void onBackPressed() {
if(mywebView.canGoBack()){
mywebView.goBack();
} else {
super.onBackPressed();
}
}}
mywebView.setWebViewClient(new WebViewClient() {
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
findViewById(R.id.progress).setVisibility(View.VISIBLE);
}
public void onPageFinished(WebView view, String url) {
findViewById(R.id.progress).setVisibility(View.GONE);
}
public void onReceivedError(WebView webview, int i, String s, String s1)
{
webview.loadUrl("file:///android_asset/error.html");
}
});
Finally I found the solution.
I'm working with Android and Phonegap, and at the moment I'm having trouble with one simple thing. I need to setup a webViewClient to the PhoneGap webView in order to capture the URL of a page finished and to work with that.
This is the code:
public class PhoneGapTest extends DroidGap {
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
super.setBooleanProperty("loadInWebView", true);
super.clearCache();
super.keepRunning = false;
super.loadUrl("file:///android_asset/www/index.html");
super.appView.setWebViewClient(new WebViewClient(){
#Override
public void onPageStarted(WebView view, String url, Bitmap bitmap) {
Log.i("TEST", "onPageStarted: " + url);
}
#Override
public void onPageFinished(WebView view, String url) {
Log.i("TEST", "onPageFinished: " + url);
}
});
}
That code doesn't seems to work, the page never loads and I get a TIMEOUT ERROR, but if I remove the "setWebViewClient" part the page loads perfectly.
I saw that there is a class CordovaWebViewClient, do I have to use that instead of WebViewClient? I found this way on the web:
this.appView.setWebViewClient(new CordovaWebViewClient(this){
#Override
public boolean shouldOverrideUrlLoading(final WebView view, String url) {
Log.i("BugTest", "shouldOverrideUrlLoading: " + url);
return true;
}
#Override
public void onPageStarted(WebView view, String url, Bitmap bitmap) {
Log.i("TEST", "onPageStarted: " + url);
}
#Override
public void onPageFinished(WebView view, String url) {
Log.i("TEST", "onPageFinished: " + url);
}
#Override
public void doUpdateVisitedHistory(WebView view, String url, boolean isReload){
}
});
But that code isn't working either, I still got a TIMEOUT ERROR.
I also saw that there is already a webVieClient member, but I don't if I have to use it and how.
I'm working with Phonegap version 1.9.0
Thanks for reading
Answer to Simon:
It worked this way, thanks!
public class MainActivity extends DroidGap {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.init();
super.appView.clearCache(true);
super.appView.clearHistory();
this.appView.setWebViewClient(new CustomCordovaWebViewClient(this));
super.loadUrl("file:///android_asset/www/index.html");
}
public class CustomCordovaWebViewClient extends CordovaWebViewClient {
public CustomCordovaWebViewClient(DroidGap ctx) {
super(ctx);
}
#Override
public void onPageStarted(WebView view, String url, Bitmap bitmap) {
super.onPageStarted(view, url, bitmap);
Log.i("TEST", "onPageStarted: " + url);
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
Log.i("TEST", "onPageFinished: " + url);
}
#Override
public void doUpdateVisitedHistory(WebView view, String url, boolean isReload){
super.doUpdateVisitedHistory(view, url, isReload);
}
#Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
}
}
}
I think I've figured this out on latest Cordova versions (I'm using 2.2). It fails at onPageStarted() because it's expecting an appView, which is null. Setting the appView seems to fix it eg
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.init();
CordovaWebViewClient webViewClient = new CustomAcceptingWebViewClient(this);
webViewClient.setWebView(this.appView);
this.appView.setWebViewClient(webViewClient);
super.loadUrl("file:///android_asset/www/index.html");
}
Note that the super.init() is also needed
To accomplish what you want to do I would extend the CordovaWebViewClient class and override the methods you want but don't forget to call the super methods or PhoneGap won't work without the CordovaWebViewClient as it is an important class.
You forgot to call super ;)
// Assign webclient.
this.appView.setWebViewClient(new CordovaWebViewClient(me, this.appView) {
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
#Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
}
});
Is there a way to set the timeout value in WebView?
I want the WebView to be timeouted if the url is too slow to response.
You can do it by setting up a Timer which checks for progress of current page by calling getProgress() and if it is less than some threshold after some specified time then you can dismiss the loading of the current page.
We can use onLoadResource method of WebViewClient instead of Timer. Like this:
webView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
progressDialog.show();
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
Log.d("WEBCLIENT", "onPageFinished");
}
#Override
public void onLoadResource(WebView view, String url) {
super.onLoadResource(view, url);
Log.d("WEBCLIENT","onLoadResource");
if(webView.getProgress() == 100) {
progressDialog.dismiss();
}
}
}
I use
#Override
public void onReceivedError(WebView view, int errorCod,String description, String failingUrl) {
final Dialog dialog = new Dialog(MainActivity.this, android.R.style.Theme_NoTitleBar_Fullscreen);
dialog.setContentView(R.layout.alert_dialog);
Button btTryAgain = dialog.findViewById(R.id.bt_try_again);
btTryAgain.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v){
recreate();
}
});
dialog.show();
//Toast with error conection
Toast.makeText(getApplicationContext(), "Your Internet Connection May not be active Or " + description , Toast.LENGTH_LONG).show();
}
Where -alert_dialog- is a layout with a button to retry