Programmatically clear browser cache / history

During my work, I send the intent to the browser to display the web page:

Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://ww.mywebpage.com"); startActivity(i); 

I need to make sure that before sending the intent, the browser cache and history are cleared so that the page loads from the server directly, and not from the phone.

So far I have found the following 2, but I'm not sure if they are used correctly:

 Browser.clearHistory(getContentResolver()); Browser.clearSearches(getContentResolver()); 

In addition, this cache is not cleared.

Do you know how to do this?

+1
source share
2 answers

Firstly, you assume that there is only one web browser for Android. You are mistaken, and with time you will be more and more mistaken. Steel, Dolphin, Opera, etc. Already released for Android, and Mozilla Fennec blends well. This solution will not help you with other browsers.

Secondly, if the browser caches your data incorrectly, your problem is probably on the server (i.e. do not send the correct cache headers). I would try to fix it there so that it works correctly in all browsers.

Thirdly, destroying the entire user's history and search queries to satisfy your requirements is rather unprofessional. How do you want a desktop application to destroy your browsing history and search queries?

Fourth, you cannot clear the browser cache programmatically.

+7
source

Yes ... and if you have more control over the client part, rather than fixing it on the server, you will need to display the content with a web view inside your application, where you have full control, and not delegate the browser (this is a separate application that works under a separate user ID and a separate security context with which you cannot communicate).

0
source

Source: https://habr.com/ru/post/1394991/


All Articles