Webview Does Not Finish Loading
Solution 1:
Try below code sequence and let me know if any issues. Don't forget to add permission to your AndroidManifest.xml
<uses-permissionandroid:name="android.permission.INTERNET" />
Change to below :
WebViewwebview= (WebView) findViewById(R.id.webView1);
webview.setWebViewClient (newHelloWebViewClient());
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("http://docs.google.com/gview?embedded=true&url=http://178.239.16.28/fzs/sites/default/files/dokumenti-vijesti/sample.pdf");
And use below snippts
privateclassHelloWebViewClientextendsWebViewClient {
@OverridepublicbooleanshouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
returntrue;
}
@OverridepublicvoidonPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
}
Solution 2:
Your url is redirecting.
You'll have to override shouldOverrideUrlLoading
Give the host application a chance to handle the key event synchronously. e.g. menu shortcut key events need to be filtered this way. If return true, WebView will not handle the key event. If return false, WebView will always handle the key event, so none of the super in the view chain will see the key event. The default behavior returns false.
Parameters
view The WebView that is initiating the callback.
event The key event.
Returns True if the host application wants to handle the key event itself, otherwise return false
Solution 3:
Use this lines ..
package org.example.webviewdemo;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
publicclassWebViewDemoextendsActivity {
privateWebView webView;
Activity activity ;
privateProgressDialog progDailog;
@SuppressLint("NewApi")
@OverridepublicvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
activity = this;
progDailog = ProgressDialog.show(activity, "Loading","Please wait...", true);
progDailog.setCancelable(false);
webView = (WebView) findViewById(R.id.webview_compontent);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.setWebViewClient(newWebViewClient(){
@OverridepublicbooleanshouldOverrideUrlLoading(WebView view, String url) {
progDailog.show();
view.loadUrl(url);
returntrue;
}
@OverridepublicvoidonPageFinished(WebView view, final String url) {
progDailog.dismiss();
}
});
webView.loadUrl("http://docs.google.com/gview?embedded=true&url=http://178.239.16.28/fzs/sites/default/files/dokumenti-vijesti/sample.pdf");
}
}
It will show loader until loading the file. then loader get hide once file have loaded using google docs. hope this will help you.
Post a Comment for "Webview Does Not Finish Loading"