Turning on internet connection programmatically (Android) -
i developing software android want turn on user's internet connection automatically. these internet on/off widgets does.
private void setmobiledataenabled(context context, boolean enabled) throws exception{ final connectivitymanager conman = (connectivitymanager) context.getsystemservice(context.connectivity_service); class conmanclass = null; try { conmanclass = class.forname(conman.getclass().getname()); } catch (classnotfoundexception e) { // todo auto-generated catch block e.printstacktrace(); } 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); }
this 3g activation similar goes wifi
Comments
Post a Comment