Thanks for that info.
getTotalRxBytes<http://developer.android.com/reference/android/net/TrafficStats.html#getTotalRxBytes()>() + getTotalTxBytes<http://developer.android.com/reference/android/net/TrafficStats.html#getTotalRxBytes()>() gives me the total bytes transferred. Does this include all data i.e. - mobile - wifi - bluetooth - anything else I can get the individual usage for mobile by using getMobileRxBytes<http://developer.android.com/reference/android/net/TrafficStats.html#getMobileRxBytes()> and getMobileTxBytes<http://developer.android.com/reference/android/net/TrafficStats.html#getMobileRxBytes()> . To get wifi usage, will the following code work? ------------------------------------------------------------------------------------ long b1 = getMobileRxBytes<http://developer.android.com/reference/android/net/TrafficStats.html#getMobileRxBytes()>() + getMobileTxBytes<http://developer.android.com/reference/android/net/TrafficStats.html#getMobileRxBytes()> (); long b2 = getTotalRxBytes<http://developer.android.com/reference/android/net/TrafficStats.html#getTotalRxBytes()>() + getTotalTxBytes<http://developer.android.com/reference/android/net/TrafficStats.html#getTotalRxBytes()> (); long wifi_usage = b2 - b1; // is this correct? ------------------------------------------------------------------------------------ Is there any other way of getting the individual usage for WiFi only? Thanks On Mon, Jan 16, 2012 at 8:33 PM, Mark Murphy <mmur...@commonsware.com>wrote: > TrafficStats can tell you the number of bytes/packets/etc. transferred > over WiFi or mobile data. > > On Mon, Jan 16, 2012 at 6:49 AM, Put_tiMe <putt...@gmail.com> wrote: > > I want to determine if the Wifi is being used currently. > > > > AFAIK, Wifi can be in a "connected" state, but there need not be any > > data being transferred currently. > > > > I can get whether the Wi-fi is connected or not by doing this: > > > > > -------------------------------------------------------------------------------------------------------------------------------- > > android.net.ConnectivityManager pCM = > > > (android.net.ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); > > if(null != pCM) > > { > > NetworkInfo aNI = > > pCM.getNetworkInfo(android.net.ConnectivityManager.TYPE_WIFI); > > if(null != aNI) > > { > > NetworkInfo.DetailedState > aDS = aNI.getDetailedState(); > > > > if(NetworkInfo.DetailedState.IDLE > == aDS || > > NetworkInfo.DetailedState.FAILED == aDS || > > > NetworkInfo.DetailedState.DISCONNECTED == aDS || > > NetworkInfo.DetailedState.SUSPENDED == aDS) > > { > > WifiManager > theWiFi = > > (WifiManager)getSystemService(WIFI_SERVICE); > > > > if(null != theWiFi) > > { > > // do something > } > > } > > else > > { > > // do something > > } > > } > > } > > > -------------------------------------------------------------------------------------------------------------------------------- > > > > But I am not able find an API if the Wifi data transfer is happening. > > Is there any way I can know this? > > > > Thanks > > > > > > > > -- > > You received this message because you are subscribed to the Google > > Groups "Android Developers" group. > > To post to this group, send email to android-developers@googlegroups.com > > To unsubscribe from this group, send email to > > android-developers+unsubscr...@googlegroups.com > > For more options, visit this group at > > http://groups.google.com/group/android-developers?hl=en > > > > -- > Mark Murphy (a Commons Guy) > http://commonsware.com | http://github.com/commonsguy > http://commonsware.com/blog | http://twitter.com/commonsguy > > Android Training in DC: http://marakana.com/training/android/ > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to android-developers@googlegroups.com > To unsubscribe from this group, send email to > android-developers+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en