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
Post a Comment