Reputation: 16547
I'm creating an app where I'm connecting to a website (with webview) which uses websockets. I occasionally want to stop the websocket connection and the site kinda supports it like when the user goes offline, it waits for user to come online again to reconnect with websocket.
Now what I'm looking for, is, can I (occasionally) programmatically disable (trigger, actually) my webview (or my app) from accessing internet? I cannot find any API or anything to achieve this.
Please don't recommend to navigate to some other page. I cannot do it because of some critical reasons.
Upvotes: 1
Views: 654
Reputation: 1283
Set WebView's cache mode to LOAD_CACHE_ONLY to disable the network and use cache only.
webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ONLY);
Upvotes: 1