android event for current network traffic? -


i want write android app polls server. assume starting network transmittion (when there no nework traffic) costs battery. might more energy efficient polling when there network traffic.

my questions:

  • is assumtion "saving battery wait until there network traffic" correct?
  • is there way find out in android right moment has come polling?

what know far:

i can register connectivity_change-broadcastreceiver informs me network status change (enabled/disabled wlan/gprs)

        intentfilter filterc = new intentfilter("android.net.conn.connectivity_change");          registerreceiver(connectivitycheckreceiver, filterc); 

here broadcast receiver

public final broadcastreceiver connectivitycheckreceiver = new broadcastreceiver() {      @override     public void onreceive(context context, intent intent) {         string action = intent.getaction();         string type;          connectivitymanager connectivitymanager = (connectivitymanager) context.getsystemservice(context.connectivity_service);         networkinfo testco = connectivitymanager.getactivenetworkinfo();         if(testco == null)             islanconnectednewvalue = false;         else             islanconnectednewvalue = true;          networkinfo networkinfo = (networkinfo) intent.getparcelableextra(connectivitymanager.extra_network_info);         if(networkinfo.gettype() == connectivitymanager.type_wifi)             type = "wifi";         else if(networkinfo.gettype() == connectivitymanager.type_mobile)             type = "umts/3g";         else             type = "other";          if(islanconnectednewvalue & !islanconnected){             // candidate polling         }         islanconnected = islanconnectednewvalue;     } }; 

is there way find out if network in use?

  • "saving battery wait until there network traffic" - correct on cellular networks, 3g - device energy state (and hence consumed energy) on these networks depends on network traffic , network-configured inactivity timeouts , more send in batch, less spend idling while consuming lot of energy.

to more precise, data transmission above small threshold (usually around 128 bytes) trigger device switch called dch state (dedicated channel) , stay there after last bit has been transmitted 5-10 seconds until going fach state (shared channel - higher latency, low throughput) , in 0 - 15 seconds go idle. variability here not random - depends on network configuration , mobile device (e.g. support fast dormancy1?) , these values can commonly seen in different networks. sum of both of these timers amount of time waste energy after each transmission.

by way, radio in dedicated channel state uses comparable amount of power of cpu, while waiting in high energy states.

  • "is there way find out in android right moment has come polling?" - not in current systems, no. can try , create clever heuristics, there no method system not report such information.

in fact, barely ever efficient polling energy perspective - try push whenever can instead, either on long-lived connection keep alive @ low (!) periodicity, or using system-native push mechanisms - systems quite optimised , cost of having link amortised across apps using service.

  • extra bit: there no apis finding out timers in particular network. if want that, however, simple way of estimating them in current network scenario playing around ping: if ping high enough frequency (e.g. 0.2 seconds), should see 3 different latencies packets: above 2000ms, few hundred ms , 60-80ms. above 2000ms means in idle state - that's how long takes signalling set 3g link. hundreds of ms means in shared state (fach) , lowest band means in dedicated, high bandwidth state (dch).

now yo should able figure out algorithm compute estimate ping, don't use ping check state in decide if time send.

edit:

although still not give information current network traffic, may want take @ android's syncadapter - gives control on framework schedule when sync operations happen.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -