Webview changing url according to day

Asked

Viewed 65 times

1

I did a blog , to use only in this app , it’s about liturgy , and every day has a liturgy , so are 365 liturgies , if I put 365 Activity the app will get very heavy , so I thought to put only one Activity with webview , wanted to know if there’s any way I can change only the webview link every day, for example , today is the 228 of the year so it will display a url , tomorrow will be the 229 so it will display another url , just changing the url’s

Below is my webview

    String url = "https://paroquiasaoroqueblog.wordpress.com/228-2/";
    wv = (WebView) findViewById(R.id.webviewnsCarmo);
    wv.getSettings().setJavaScriptEnabled(true);
    wv.getSettings().setPluginState(WebSettings.PluginState.ON);
    wv.getSettings().setAllowFileAccess(true);
    wv.setWebViewClient(new MyWebViewClient());
    wv.loadUrl(url);
    wv.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);

Obs : the 2 in the webview link is disregarded as it is automatically generated by the blog when publishing

1 answer

4


You can concatenate the current day of the year to your URL using the class Calendar.

Example:

Calendar c = Calendar.getInstance();
String url = "https://paroquiasaoroqueblog.wordpress.com/" + c.get(Calendar.DAY_OF_YEAR) + "-2/";

Browser other questions tagged

You are not signed in. Login or sign up in order to post.