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

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -