I want to restrict 3G access to a single domain (my system) to save on 3G access for employees. But if the employee access via WIFI can be all released (because there will be no extra cost). Is there any way you can do this?
I want to restrict 3G access to a single domain (my system) to save on 3G access for employees. But if the employee access via WIFI can be all released (because there will be no extra cost). Is there any way you can 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");
iConnectivityManagerField.setAccessible(true);
final Object iConnectivityManager = iConnectivityManagerField.get(conman);
final Class iConnectivityManagerClass = Class.forName(iConnectivityManager.getClass().getName());
final Method setMobileDataEnabledMethod = iConnectivityManagerClass.getDeclaredMethod("setMobileDataEnabled", Boolean.TYPE);
setMobileDataEnabledMethod.setAccessible(true);
setMobileDataEnabledMethod.invoke(iConnectivityManager, enabled);
}
And let us know about this in your Manifest:
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>