Android restriction – 3g


I want to restrict 3G access to a single domain (my system's) to save employees 3G access. But if the employee accesses via WIFI, everything can be freed up (because then there will be no extra cost). Is there any way to do this?


You can do it this way:

    private void setMobileDataEnabled(Context context, boolean enabled) {
        final ConnectivityManager conman = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        final Class conmanClass = Class.forName(conman.getClass().getName());
        final Field iConnectivityManagerField = conmanClass.getDeclaredField("mService");
        final Object iConnectivityManager = iConnectivityManagerField.get(conman);
        final Class iConnectivityManagerClass = Class.forName(iConnectivityManager.getClass().getName());
        final Method setMobileDataEnabledMethod = iConnectivityManagerClass.getDeclaredMethod("setMobileDataEnabled", Boolean.TYPE);

        setMobileDataEnabledMethod.invoke(iConnectivityManager, enabled);

And inform this excerpt in your Manifest:

    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
Scroll to Top