retrofit - Android use only cellular(3G, 4G, EDGE) data for server requests -


i have app , i'd use cellular data server requests. don't need disable wi-fi completely like:

  wifimanager wifimanager = (wifimanager) context.getsystemservice(context.wifi_service);   wifimanager.setwifienabled(false); 

maybe there a way app. note i'm using retrofit okhttp client, smth like:

    private static void setuprestclient() {          okhttpclient client = new okhttpclient();         client.setconnecttimeout(5, timeunit.seconds);         client.setreadtimeout(5, timeunit.seconds);         client.setretryonconnectionfailure(true);          restadapter restadapter = new restadapter.builder()                 .setloglevel(restadapter.loglevel.full)                 .setendpoint(new endpointmanager())                 .setclient(new okclient(client))                 .build();      } 

check app connected wifi , prevent requests happening follows:

public static boolean isonwifi(context context) {     connectivitymanager connmanager = (connectivitymanager) context.getsystemservice(context.connectivity_service);     networkinfo mwifi = connmanager.getnetworkinfo(connectivitymanager.type_wifi);     return mwifi.isconnected(); } 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

Maven Javadoc 'Cannot find default setter' and fails -