performance - Set mobile data enabled via android code on switch button -


i tried following method:

public void mobiledataenable(boolean enabled) {      try {         final connectivitymanager conman = (connectivitymanager)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);     }     catch (exception e)     {         e.printstacktrace();     } } 

added following permissions:

**uses-permission android:name="android.permission.read_phone_state" uses-permission android:name="android.permission.access_coarse_location" 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"** 

and called setoncheckedchangelistener

still not getting internet on.

i want code or other code work api 19 , above.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo