For accessing the WIFI state :
WifiManager wifiManager ;
wifiManager = (WifiManager)this.getSystemService(this.WIFI_SERVICE);
wifiManager.setWifiEnabled(true); //True - to enable WIFI connectivity .
For accessing the DATA/3G state :
ConnectivityManager dataManager;
dataManager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
Method dataMtd = ConnectivityManager.class.getDeclaredMethod("setMobileDataEnabled", boolean.class);
dataMtd.setAccessible(true);
dataMtd.invoke(dataManager, true); //True - to enable data connectivity .
Now you need to add this permissions in Manifest file :
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
sir what kind of program to edit/make these?
ReplyDeleteThis comment has been removed by the author.
ReplyDeletedid u put the uses-permission on manifest file ....
DeleteMethod cannot be resolved to a type
ReplyDeleteSir,
ReplyDeleteI need an android wifi application that shows the scanned networks in a selected list view...so that after scanning when it shows available networks and when we select it ...it gets connected to any one...pls help me,,,am so stressed because of this...
How to enable mobile internet data programatically?
DeleteHi !! How can I do this in ruby ? Thank you !
ReplyDeleteHi, marshmallow it is not working
ReplyDeleteHow to turn off data connection programmatically
ReplyDelete