views:

148

answers:

2

Hello! Is there a (simple) possibility for turning the mobile network on/off with Java code? If so, for mobile service too? 'Cause I'd like to make an app which turns the network on and service off (or the opposite).

Thanks for help.

+2  A: 

The wireless network you can turn on by the following code:

WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifiManager.setWifiEnabled(true);
Roflcoptr
Thanks, but if I try my app crashes while executing the code above.
Daichan
could you post the exception? maybe you havent add<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>to the manifest. i should have mentioned that. sorry.
Roflcoptr
A: 

You need permissions to do that. I think CHANGE_WIFI_STATE is the right one.

molnarm
I'm quite a beginner, how do i put this?
Daichan
Ah, found out myself, just had to add this into the AndroidManifest.xmlThanks, guys!
Daichan