0

How do I refresh the contents of a webview? That's my code THERE IS A WAY to update it? there a way to update the page automatically? thanks a lot

public class MainActivity extends Activity implements AdvancedWebView.Listener {

private static final String TEST_PAGE_URL = "";
private AdvancedWebView mWebView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mWebView = (AdvancedWebView) findViewById(R.id.webview);
    mWebView.setListener(this, this);
    mWebView.setGeolocationEnabled(false);
    mWebView.setMixedContentAllowed(true);
    mWebView.setCookiesEnabled(true);
    mWebView.setThirdPartyCookiesEnabled(true);
    mWebView.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageFinished(WebView view, String url) {
            Toast.makeText(MainActivity.this, "Finished loading", Toast.LENGTH_SHORT).show();
        }

    });
    mWebView.setWebChromeClient(new WebChromeClient() {

        @Override
        public void onReceivedTitle(WebView view, String title) {
            super.onReceivedTitle(view, title);
            Toast.makeText(MainActivity.this, title, Toast.LENGTH_SHORT).show();
        }

    });
    mWebView.addHttpHeader("X-Requested-With", "");
    mWebView.loadUrl("");
}

@SuppressLint("NewApi")
@Override
protected void onResume() {
    super.onResume();
    mWebView.onResume();
    // ...
}

@SuppressLint("NewApi")
@Override
protected void onPause() {
    mWebView.onPause();
    // ...
    super.onPause();
}

@Override
protected void onDestroy() {
    mWebView.onDestroy();
    // ...
    super.onDestroy();
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);
    mWebView.onActivityResult(requestCode, resultCode, intent);
    // ...
}

@Override
public void onBackPressed() {
    if (!mWebView.onBackPressed()) { return; }
    // ...
    super.onBackPressed();
}

@Override
public void onPageStarted(String url, Bitmap favicon) {
    mWebView.setVisibility(View.INVISIBLE);
}

@Override
public void onPageFinished(String url) {
    mWebView.setVisibility(View.VISIBLE);
}

@Override
public void onPageError(int errorCode, String description, String failingUrl) {
    Toast.makeText(MainActivity.this, "onPageError(errorCode = "+errorCode+",  description = "+description+",  failingUrl = "+failingUrl+")", Toast.LENGTH_SHORT).show();
}

@Override
public void onDownloadRequested(String url, String suggestedFilename, String mimeType, long contentLength, String contentDisposition, String userAgent) {
    Toast.makeText(MainActivity.this, "onDownloadRequested(url = "+url+",  suggestedFilename = "+suggestedFilename+",  mimeType = "+mimeType+",  contentLength = "+contentLength+",  contentDisposition = "+contentDisposition+",  userAgent = "+userAgent+")", Toast.LENGTH_LONG).show();

    /*if (AdvancedWebView.handleDownload(this, url, suggestedFilename)) {
        // download successfully handled
    }
    else {
        // download couldn't be handled because user has disabled download manager app on the device
    }*/
}
@Override
public void onExternalPageRequest(String url) {
    Toast.makeText(MainActivity.this, "onExternalPageRequest(url = "+url+")", Toast.LENGTH_SHORT).show();
}
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Samir20
  • 11
  • 1
  • Possible duplicate of [How do I refresh the contents of a webview everytime the app is launched?](http://stackoverflow.com/questions/29994509/how-do-i-refresh-the-contents-of-a-webview-everytime-the-app-is-launched) –  Apr 02 '17 at 22:31

1 Answers1

0

A WebView has a reload method that you can call. This will reload the current url.

https://developer.android.com/reference/android/webkit/WebView.html#reload()

It is not exactly clear on when you want to refresh but you would need to put this somewhere in your code: mWebView.reload();

michaelcarrano
  • 1,316
  • 2
  • 12
  • 19
  • thanks for the reply, I put the code, but does not work exmple code that I put mWebView.reload();("exmple.com"); – Samir20 Apr 02 '17 at 22:45