blob: 6fb7d8a9a4883f756845428761bfff1a6c407ed3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
package se.leap.bitmaskclient.test;
import android.content.*;
import android.net.*;
import android.net.wifi.*;
import java.lang.reflect.*;
public class ConnectionManager {
static void setMobileDataEnabled(boolean enabled, Context context) {
final ConnectivityManager conman = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
Method[] methods = conman.getClass().getMethods();
for (Method method : methods) {
if (method.getName().equals("setMobileDataEnabled")) {
method.setAccessible(true);
try {
method.invoke(conman, enabled);
} catch (InvocationTargetException e) {
//e.printStackTrace();
} catch (IllegalAccessException e) {
//e.printStackTrace();
}
}
}
}
static void setWifiEnabled(boolean enabled, Context context) {
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
wifiManager.setWifiEnabled(enabled);
}
}
|