Disable/Block Internet Access from Android Phone
The scenario is, i'm developing an android app that uses the internet. This is a business app. The company will provide android phones to all the employees. Now their requirement is that they don't want employees to use the internet by other means than by their business app, which requires internet access.
In short i need to develop an app that disable the internet (wifi, mobile data etc.) and allow internet only when user is using this App.
Is this possible? How to achieve this? A service that will always be keeping a check on network connectivity?
Any help is appreciated.
Im using BroadcastReciever, that detects Connection State and disables the Wifi. How can i detect Connected state of mobile Data, i mean what is the intent filter action to detect mobile data connection and then disable it accordingly, i have tried
This is something not suggestable but if you still want to do so,
in onCreate of each activity which uses Internt write this code,
WifiManager wifiManager = (WifiManager)this.context.getSystemService(Context.WIFI_SERVICE); wifiManager.setWifiEnabled(true);
and in onPause of that activty write,
WifiManager wifiManager = (WifiManager)this.context.getSystemService(Context.WIFI_SERVICE); wifiManager.setWifiEnabled(false);
this is to do for WIFI for GPRS/EDGE/3G you might will have to enable disable Airplane mode same way.
UPDATE TO DO IT FROM EVERYWHERE
Take one SharedPreference and put one boolean isAppRunning = true every time you go in onCreate() of any of your activity and put False everytime in each activity's onDestroy() method.
Now, Create one broadcast receiver that listend to NETWORK_STATE_CHANGED action and in that receiver's onReceive() check for the SharedPreference value,
If SP boolean variable is True then Let the WIFI get enabaled and If it's false means your app is not running then toggle the WIFI off again.