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.
UPDATE:
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
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
This is something not suggestable but if you still want to do so,
in onCreate of each activity which uses Internt write this code,
and in onPause of that activty write,
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
SharedPreferenceand put oneboolean isAppRunning = trueevery time you goin onCreate()of any of your activity and putFalseeverytime in each activity’sonDestroy()method.Now, Create one broadcast receiver that listend to
NETWORK_STATE_CHANGEDaction and in that receiver’sonReceive()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.