Android: Add Timestamp to URL for WebView

梦想的初衷 提交于 2020-01-06 08:59:27

问题


For starters, I am not a programmer, my wife is making me learn how to program for Android because she wants me to make her some apps to use around the house.

I have a basic app that loads a JPG into a WebView window. I read that in order to help manage caching it's a good idea to add a timestamp to a URL.

I am not sure how to add a Timestamp into the URL.

This is what I have now:

mWebView.loadUrl("http://www.website.com/webviewimage.jpg"+"?123");

I plan to replace the "?123" with the Timestamp, but I'm not sure how to type this in. I have this in the beginning of my code so hopefully, I'm thinking I'm halfway there.:

import java.sql.Timestamp;

Thank you so much for your help.

Cheers,

Pat


回答1:


This will put the current time in milliseconds on to the end of your URL.

mWebView.loadUrl("http://www.website.com/webviewimage.jpg?" + System.currentTimeMillis());


来源:https://stackoverflow.com/questions/5944632/android-add-timestamp-to-url-for-webview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!