How to load the data in webview page by page in android - android

I am using webview to display the html data.It is working fine if the data is less(less than 1 mb)..I am using following code
mDecryptDataWv.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
DebugLog.i(TAG, "Processing webview url click...");
view.loadUrl(url);
return true;
}
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// TODO Auto-generated method stub
//showProgressDialog();
DebugLog.i(TAG, "************onPageStarted **************");
}
#Override
public void onPageFinished(WebView view, String url) {
DebugLog.i(TAG, "************onPageFinished **************");
if (mProgressDialog != null) {
if (mProgressDialog.isShowing()) {
DebugLog.i(TAG, "mProgressDialog ::::::stopping");
mProgressDialog.dismiss();
mProgressDialog = null;
}
}
If the data is more then 1MB it is taking more time to complete the loading.so my intention is to load the data page by page upon user scrolling with progress dialog..Can anyone has idea?

// I used this class and my code is working fime at my side please try this may be it will help you
public class WebViewActivity extends Activity {
private WebView webview;
private static final String TAG = "Main";
private ProgressDialog progressBar;
private TextView header_maintext;
private TextView headeroptiontext;
private RelativeLayout back;
private String url_string="http://www.google.com";
private String header_maintext_string="Your text";
/** Called when the activity is first created. */
#SuppressLint("SetJavaScriptEnabled") #Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.webview_layout);
webview = (WebView)findViewById(R.id.webview01);
header_maintext= (TextView)findViewById(R.id.header_maintext);
header_maintext.setText(header_maintext_string);
headeroptiontext = (TextView)findViewById(R.id.headeroptiontext);
headeroptiontext.setVisibility(View.GONE);
WebSettings settings = webview.getSettings();
settings.setJavaScriptEnabled(true);
webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webview.getSettings().setLoadWithOverviewMode(true);
webview.getSettings().setUseWideViewPort(true);
back = (RelativeLayout) findViewById(R.id.back_layout);
back.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0)
{
// TODO Auto-generated method stub
if(webview.canGoBack() == true)
{
webview.goBack();
}
else
{
finish();
}
}
});
final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
progressBar = ProgressDialog.show(WebViewActivity.this, "My application", "Loading...");
webview.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
public void onPageFinished(WebView view, String url) {
Log.i(TAG, "Finished loading URL: " +url);
if (progressBar.isShowing()) {
progressBar.dismiss();
}
}
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(WebViewActivity.this, "Oh no! " + description, Toast.LENGTH_SHORT).show();
alertDialog.setTitle("Error");
alertDialog.setMessage(description);
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
return;
}
});
alertDialog.show();
}
});
webview.loadUrl(url_string);
}
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(event.getAction() == KeyEvent.ACTION_DOWN){
switch(keyCode)
{
case KeyEvent.KEYCODE_BACK:
if(webview.canGoBack() == true){
webview.goBack();
}else{
finish();
}
return true;
}
}
return super.onKeyDown(keyCode, event);
}
}

Related

Android Studio Webview login cache

my webview app opens a website that i need to login. but if i login and destroy the app, i need to login again. i want to cache login data and no need to login again until i log out. how can i make the webview app like holding caches? if user dont logout, app must to stay logged in. thanks for helping
here is my code:
WebView webid;
String newString;
ImageView loading;
AnimationDrawable animation;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webid = (WebView) findViewById(R.id.webid);
loading = (ImageView)findViewById(R.id.loader);
animation = (AnimationDrawable) loading.getDrawable();
WebSettings webSettings = webid.getSettings();
webSettings.setJavaScriptEnabled(true);
webid.loadUrl("https://ios.mavicell.com");
webid.setWebViewClient(new WebViewClient(){
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
loading.setVisibility(View.VISIBLE);
animation.start();
}
#Override
public void onPageCommitVisible(WebView view, String url) {
super.onPageCommitVisible(view,url);
loading.setVisibility(View.INVISIBLE);
animation.stop();
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
loading.setVisibility(View.INVISIBLE);
animation.stop();
}
});
if (savedInstanceState == null) {
Bundle extras = getIntent().getExtras();
if(extras == null) {
newString= null;
} else {
newString= extras.getString("urlayar");
}
} else {
newString= (String) savedInstanceState.getSerializable("urlayar");
}
if (newString != null) {
webid.loadUrl(newString);
webid.getSettings().setJavaScriptEnabled(true);
webid.setWebViewClient(new WebViewClient(){
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
loading.setVisibility(View.VISIBLE);
animation.start();
}
#Override
public void onPageCommitVisible(WebView view, String url) {
super.onPageCommitVisible(view,url);
loading.setVisibility(View.INVISIBLE);
animation.stop();
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
loading.setVisibility(View.INVISIBLE);
animation.stop();
}
});
}
else {
}
// Logging set to help debug issues, remove before releasing your app.
OneSignal.setLogLevel(OneSignal.LOG_LEVEL.VERBOSE, OneSignal.LOG_LEVEL.NONE);
// OneSignal Initialization
OneSignal.startInit(this)
.inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
.unsubscribeWhenNotificationsAreDisabled(true)
.init();
}
#Override
public boolean onKeyDown(int keyCode, #NonNull KeyEvent event){
if(event.getAction() == KeyEvent.ACTION_DOWN){
if (keyCode == KeyEvent.KEYCODE_BACK) {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Mavicell");
builder.setMessage("Çıkmak istediğinize emin misiniz?");
builder.setNegativeButton("Hayır", null);
builder.setPositiveButton("Evet", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
finish();
}
});
builder.show();
return true;
}
}
return super.onKeyDown(keyCode, event);
}
This below line should do your work
webSettings.setCacheMode(WebSettings.LOAD_DEFAULT)

I want to open URL with webview, but when I tried to login in that site, I can't login

When I tried to login it shows a popup window and asking for email and password
when I entered my correct email and password and click on login it doesn't redirect to my account it only shows the same page
this is my MainActivity
you can also download my application for better understanding my problems https://play.google.com/store/apps/details?id=in.bidforx.bidforx
use email: anup.gorai.9835#gmail.com
password:78907890
private ProgressBar progressBar;
private WebView webView;
#SuppressLint("SetJavaScriptEnabled")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AppRate.with(this)
.setInstallDays(0)
.setLaunchTimes(3)
.setRemindInterval(0)
.monitor();
AppRate.showRateDialogIfMeetsConditions(this);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
progressBar.setMax(100);
webView = (WebView) findViewById(R.id.webView);
webView.setWebViewClient(new WebViewClientDemo());
webView.setWebChromeClient(new WebChromeClientDemo(
));
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setAppCacheEnabled(true);
webView.loadUrl("https://bidforx.com");
if (Build.VERSION.SDK_INT>=21){
CookieManager.getInstance().setAcceptThirdPartyCookies(webView,true);
}else{ CookieManager.getInstance().setAcceptCookie(true);}
webView.getSettings().setSupportMultipleWindows(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView webView, int errorCode, String description, String failingUrl) {
try {
webView.stopLoading();
} catch (Exception e) {
}
if (webView.canGoBack()) {
webView.goBack();
}
webView.loadUrl("about:blank");
AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
alertDialog.setTitle("Error");
alertDialog.setMessage("Check your internet connection and try again.");
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "Try Again", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
finish();
startActivity(getIntent());
}
});
alertDialog.show();
super.onReceivedError(webView, errorCode, description, failingUrl);
}
});
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent myIntent=new Intent(Intent.ACTION_SEND);
myIntent.setType("text/plain");
String shareBody="Add World ";
String shareSub="Download the BidForx App and Buy everthing in 1% Download the App now https://play.google.com/store/apps/details?id=in.bidforx.bidforx";
myIntent.putExtra(Intent.EXTRA_TEXT,shareBody);
myIntent.putExtra(Intent.EXTRA_TEXT,shareSub);
startActivity(Intent.createChooser(myIntent,"Share using"));
}
});
}
private class WebViewClientDemo extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
progressBar.setVisibility(View.GONE);
progressBar.setProgress(100);
}
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
progressBar.setVisibility(View.VISIBLE);
progressBar.setProgress(0);
}
}
private class WebChromeClientDemo extends WebChromeClient {
public void onProgressChanged(WebView view, int progress) {
progressBar.setProgress(progress);
}
}
// on back pressed
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
webView.goBack();
return true;
}
else {
finish();
}
return super.onKeyDown(keyCode, event);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
return true;
}
}
When I try to login, I am getting an error
"Uncaught TypeError: Cannot read property 'username' of null", source: https://bidforx.com/js/login.js (2)
There must be some problem in login.js line 2. In line 2 you try to call localStorage, and somehow you can login with browser but not with app.
I haven't tried it yet but you should allow WebView to use HTML5 local storage feature first and see if you can login with app.
webView.getSettings().setDomStorageEnabled(true);
and I think you should do the item checking like this:
if (localStorage.hasOwnProperty("username")) {
//
}
in order to prevent TypeError

Android progressbar inside WebView

To create a webView recently I was using webViewClient. mWebView.setWebViewClient(new WebViewClient());
But I need to implement a progress bar. When user clicks a link, this progress bar will be visible. After page complete, progressbar will be hidden and webView will be visible. Regarding to this and this, So I added a WebChromeClient. But it loads first URL, but when I click a button inside my web page, a dialog opens and asks to open URL with which application.
I read that I should override shouldOverrideUrlLoading() method. but I get an error that "shouldOverrideUrlLoading" can't be overriden for WebChromeClient.
I would be happy if you can give an example that has progressbar and webView, also opens new URLs inside the same webView.
public class WebActivity extends Activity {
WebView mWebView;
ProgressBar mProgress;
Context mContext;
ProgressBar mProgressBar;
#Override
public void onCreate(Bundle savedInstanceState) {
this.mContext = getApplicationContext();
super.onCreate(savedInstanceState);
setContentView(R.layout.web);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.setWebChromeClient(new myWebChromeClient());
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setUserAgentString("myApp");
mProgressBar = (ProgressBar) findViewById(R.id.webProgressBar);
mProgressBar.setMax(100);
}
public class myWebChromeClient extends WebChromeClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
#Override
public void onProgressChanged(WebView view, int newProgress) {
//WebActivity.this.setValue(newProgress);
super.onProgressChanged(view, newProgress);
}
}
}
try with this code
webView = (WebView) view.findViewById(R.id.transcationwebview);
progressdialog = ProgressDialog.show(mContext, "",
mContext.getString(R.string.please_wait));
progressdialog.setCancelable(true);
progressdialog.setOnCancelListener(new OnCancelListener() {
#Override
public void onCancel(DialogInterface dialog) {
webView.stopLoading();
// webView.clearView();
}
});
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebChromeClient(new MyChromeClient());
webView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
view.loadUrl(url);
return super.shouldOverrideUrlLoading(view, url);
}
#Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
super.onPageFinished(view, url);
if (progressdialog != null && progressdialog.isShowing()) {
progressdialog.dismiss();
} else {
}
}
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// TODO Auto-generated method stub
super.onPageStarted(view, url, favicon);
}
#Override
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
// TODO Auto-generated method stub
super.onReceivedError(view, errorCode, description, failingUrl);
}
});
webView.loadUrl("url");
webView.getSettings().setBuiltInZoomControls(true);
public class MyChromeClient extends WebChromeClient {
#Override
public void onProgressChanged(WebView view, int newProgress) {
try {
if (progressdialog.isShowing()) {
progressdialog.setMessage(getString(R.string.loading)
+ newProgress + " %");
} else {
/*
* webView.stopLoading(); webView.clearView();
*/
}
} catch (Throwable e) {
e.printStackTrace();
}
}
}
you can extends WebViewClient instead of WebChromeClient and override the onPageStarted to show the ProgressBar and dismiss it in onPageReceived
I made some changes in the Activity.
use WebViewClient instead of WebChromeClient
and also use ProgressDialog instead of ProgressBar
public class WebActivity extends Activity {
WebView mWebView;
Context mContext;
ProgressDialog mProgressBar;
private static final int DIALOG2_KEY = 1;
#Override
public void onCreate(Bundle savedInstanceState) {
this.mContext = getApplicationContext();
super.onCreate(savedInstanceState);
setContentView(R.layout.web);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.setWebViewClient(new MyWebChromeClient());
mWebView.getSettings().setBuiltInZoomControls(true);
showDialog(DIALOG2_KEY); }
#Override
protected void onResume() {
super.onResume();
mWebView.loadUrl("YOUR_URL");
}
private final class MyWebChromeClient extends WebViewClient {
#Override
public void onPageFinished(WebView view, String url) {
dismissDialog(DIALOG2_KEY);
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.startsWith("file")) {
return false;
} else{
view.loadUrl(url);
return true;
}
}
}
#Override
protected Dialog onCreateDialog(int id) {
switch (id)
{
case DIALOG2_KEY:
{
mProgressBar.setMessage("Loading");
mProgressBar.setIndeterminate(true);
mProgressBar.setCancelable(false);
return mProgressBar;
}
}
return null;
}
}
Hope this help you

How to listen to webview url click and enable/disable buttons on actionbar

I'm developing an application in which I'm using webview to load certain websites. I also have customized actionbar on which I have website navigation button. Here is the view how my layout is looking like:
When I load website my all three buttons are visible, but I want them to be visible at that time only when user has clicked on some URL, so user easily understand the purpose of those buttons.
I have added all the functionalities to those button. Here is my code:
website_back = (ImageButton) cView.findViewById(R.id.website_back);
website_forward = (ImageButton) cView.findViewById(R.id.website_forward);
website_refresh = (ImageButton) cView.findViewById(R.id.website_refresh);
if (v.getId() == R.id.website_back) {
webview.goBack();
}
if (v.getId() == R.id.website_forward) {
webview.goForward();
}
if (v.getId() == R.id.website_refresh) {
webview.reload();
}
My WebViewClient:
private class HelloWebViewClient extends WebViewClient {
public void onPageStarted(WebView view, String url, Bitmap favicon) {
progress.setVisibility(View.VISIBLE);
super.onPageStarted(view, url, favicon);
}
public void onPageFinished(WebView view, String url) {
progress.setVisibility(View.GONE);
super.onPageFinished(view, url);
}
public boolean shouldOverrideUrlLoading(WebView view, String url) {
website_back.setImageResource(R.drawable.webview_back);
view.loadUrl(url);
return true;
}
}
How can I only show those buttons when user has clicked on some URL, on the website launched in the webview?
Any kind of help will be appreciated.
You need to attach a WebViewClient to the WebView to listen in on the URLs that are being fetched.
mWebView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(url.equals(mOriginalUrl)){
//initial url load, ignoring.
}
else {
//url was navigated to - do something
}
return super.shouldOverrideUrlLoading(view, url);
}
#Override
public void onPageFinished(WebView view, String url) {
//page has finished loading
}
});
this worked for me. hope it would be useful for you. try this
ExternalSiteActivity.class
public class ExternalSiteActivity extends Activity{
WebView webView;
String productURL;
ProgressBar progressBar;
ImageButton webBackButton;
ImageButton webForwButton;
ImageButton webRefreshButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.external_site_activity);
productURL= (String) getIntent().getStringExtra("productUrl");
System.out.println(productURL+"**********");
progressBar=(ProgressBar)findViewById(R.id.progress);
progressBar.setVisibility(View.INVISIBLE);
webView = (WebView) findViewById(R.id.webview);
webBackButton=(ImageButton)findViewById(R.id.web_back_button);
webForwButton=(ImageButton)findViewById(R.id.web_forw_button);
webRefreshButton=(ImageButton)findViewById(R.id.web_refresh_button);
webView.setWebViewClient(new MyWebViewClient());
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl(productURL);
webBackButton.setOnClickListener( new View.OnClickListener(){
#Override
public void onClick(View v) {
if(webView.canGoBack())
webView.goBack();
}
});
webForwButton.setOnClickListener( new View.OnClickListener(){
#Override
public void onClick(View v) {
if(webView.canGoForward())
webView.goForward();
}
});
webRefreshButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
webView.reload();
}
});
}
private class MyWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
Log.v("shouldOverrideUrlLoading", "shouldOverrideUrlLoading");
return true;
}
#Override
public void onFormResubmission(WebView view, Message dontResend,
Message resend) {
Log.v("onFormResubmission", "onFormResubmission");
}
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// TODO Auto-generated method stub
if(webView.canGoBack())
{
webBackButton.setEnabled(true);
}
else
{
webBackButton.setEnabled(false);
}
if(webView.canGoForward())
{
webForwButton.setEnabled(true);
}
else
{
webForwButton.setEnabled(false);
}
progressBar.setVisibility(View.VISIBLE);
Log.v("onPageStarted", "onPageStarted");
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
progressBar.setVisibility(View.INVISIBLE);
}
#Override
public void onLoadResource(WebView view, String url) {
Log.v("on load ","load resources----");
}
// To handle "Back" key press event for WebView to go back to previous screen.
}
#Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
webView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
}

Progress Dialog In Webview

Simply put how can I make a progress dialog show up every time a new link is clicked in my webview. I have tried many tutorials and methods but every one of them only shows the dialog once, when the app is initially loaded.
Here is my code
mWebView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return true;
}
ProgressDialog dialog = ProgressDialog.show(myActivity.this, "",
"Loading. Please wait...", true);
#Override
public void onPageFinished(WebView view, String url) {
dialog.dismiss();
}
check out this:
wvCouponsAndOffers.setWebViewClient(new WebViewClient() {
ProgressDialog progressDialog = new ProgressDialog(CouponsWebViewUI.this);
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
progressDialog.setMessage(StringConstants.PROGRESS_DIALOG_MSG);
progressDialog.setCancelable(false);
progressDialog.setOnKeyListener(new OnKeyListener(){
#Override
public boolean onKey(DialogInterface dialog, int keyCode,
KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_SEARCH) {
return true;
}
else
return false;
}});
progressDialog.show();
}
public boolean shouldOverrideUrlLoading(WebView view, String url) {
progressDialog.setMessage(StringConstants.PROGRESS_DIALOG_MSG);
progressDialog.setCancelable(false);
progressDialog.setOnKeyListener(new OnKeyListener(){
#Override
public boolean onKey(DialogInterface dialog, int keyCode,
KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_SEARCH) {
return true;
}
else
return false;
}});
progressDialog.show();
view.loadUrl(url);
return true;
}
public void onPageFinished(WebView view, String url) {
if (progressDialog.isShowing()) {
progressDialog.dismiss();
}
}
});
Try this,
// Let's display the progress in the activity title bar, like the
// browser app does.
getWindow().requestFeature(Window.FEATURE_PROGRESS);
webview.getSettings().setJavaScriptEnabled(true);
final Activity activity = this;
webview.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
// Activities and WebViews measure progress with different scales.
// The progress meter will automatically disappear when we reach 100%
activity.setProgress(progress * 1000);
}
});
webview.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
}
});
webview.loadUrl("http://slashdot.org/");
And if you want to make your own progressDialog then
webView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
// Start PROGRESS DIALOG
view.loadUrl(url);
return true;
}
#Override
public void onPageFinished(WebView view, String url) {
//HIDE PROGRESS DIALOG LOADING IT HAS FINISHED
}
});
And let me know what happen..
Try this easiest one,it work for me
public class HomeWebViewActivity extends AppCompatActivity{
private String weburl;
private WebView webview;
private Toolbar toolbar;
private ProgressDialog prDialog;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home_webview_activity);
toolbar = (Toolbar) findViewById(R.id.toolbar_homewebview);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
weburl="ADD YOUR URL HERE";
webview = (WebView) findViewById(R.id.webviewinfo);
webview.setWebViewClient(new WebVwClientcls());
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
webview.loadUrl(weburl);
}
private class WebVwClientcls extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
prDialog = new ProgressDialog(HomeWebViewActivity.this);
prDialog.setMessage("Please wait ...");
prDialog.show();
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
if(prDialog!=null){
prDialog.dismiss();
}
}
}
}

Categories

Resources