Disable / block Internet access from Android phone

Scenario: I am developing an Android application using the Internet. This is a business application. The company will provide Android phones to all employees. Now their requirement is that they do not want employees to use the Internet in other ways than their business application, which requires Internet access.

In short, I need to develop an application that disables the Internet (Wi-Fi, mobile data, etc.) and allows Internet access only when the user uses this application.

Is it possible? How to achieve this? A service that will always check network connectivity?

Any help is appreciated.

UPDATE:

Im using BroadcastReciever, which detects the connection status and disables Wi-Fi. How can I detect the state of connected mobile data, I mean, what is the intent filter action to detect a mobile data connection, and then disconnect it accordingly, I tried

<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>

+4
source share
1 answer

This is something incomprehensible, but if you still want to do it,

in onCreate of each action that Internt uses, writes this code,

 WifiManager wifiManager = (WifiManager)this.context.getSystemService(Context.WIFI_SERVICE); wifiManager.setWifiEnabled(true); 

and in onPause activity record,

 WifiManager wifiManager = (WifiManager)this.context.getSystemService(Context.WIFI_SERVICE); wifiManager.setWifiEnabled(false); 

this needs to be done for WIFI for GPRS / EDGE / 3G, you may have to enable disable flight mode in the same way.

UPDATE TO DO FROM EVERYONE

Take one SharedPreference and put one boolean isAppRunning = true every time you go in onCreate() any of your actions and every time put False in every kind of onDestroy() activity.

Now create one broadcast receiver that listens for the NETWORK_STATE_CHANGED action and in this receiver onReceive() checks the value of SharedPreference,

If the boolean variable SP is True, then let WIFI get enabaled, and if false - your application does not work, then turn off WIFI again.

0
source

All Articles