Switch to mobile network:
As soon as you detect a proxy, pop up a dialog telling the user that your app cannot use that network and hence you are switching to the mobile network. You can switch to a mobile network using ConnectivityManager
class.
ConnectivityManager cm;
cm = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
cm.setNetworkPreference(ConnectivityManager.TYPE_MOBILE);
and switch back to the default when you are done:
cm.setNetworkPreference(ConnectivityManager.DEFAULT_NETWORK_PREFERENCE);
Detect a proxy:
Detect proxy using the following snippet
HttpURLConnection conn;
...
if (conn.getResponseCode() == HTTP_PROXY_AUTH){
// You got a '407: Proxy authentication required' response.
// Set the networkPreference() here and retry when
// network connection changes to TYPE_MOBILE.
}
You can check this post to know how to use a HttpURLConnection through a proxy : How do I make HttpURLConnection use a proxy?
Detect a 'network change':
To know how to detect 'network change' see this post :
Android, How to handle change in network (from GPRS to Wi-fi and vice-versa) while polling for data
Update:
If you cannot show a dialog, at least send a status bar Notification
so that user knows about the network switch sometime later.