Re: Disable data/ wifi connection with code

110 views
Skip to first unread message

naveed

unread,
Jun 10, 2013, 3:07:38 AM6/10/13
to robotium-...@googlegroups.com
I'll try to run your code at my side, but I remember once did this using WifiManager class, can you have look into this class. 

On Saturday, June 8, 2013 3:09:58 PM UTC+5, shrikant pawar wrote:
Hi,

Can anybody help me out with disabling the data connection within the code..

This does the work, but then the connection of the device / emulator is broken with ADB.

   final ConnectivityManager conman = (ConnectivityManager) context.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); 


Please help me with this.

Thanks 

Reply all
Reply to author
Forward
0 new messages