Android devices typically have multiple data connections:
(1) Bluetooth
(2) Ethernet
(3) Wi-Fi
(4) WiMax
(5) mobile network (EDGE,UMTS,LTE)
Get Network information:
public class NetInfo extends Activity {private TextView netinfoshow,netinfoshows; @Overrideprotected void OnCreate ( Bundle savedinstancestate) {//TODO auto-generated method Stubsuper.oncreate (savedinstancestate); Setcontentview ( R.layout.net_info); netinfoshow = (TextView) Findviewbyid (r.id.net_show); netinfoshows = (TextView) Findviewbyid ( R.id.nets_show); Shownetworkinfotoast ();} private void Shownetworkinfotoast () {Connectivitymanager cm = (Connectivitymanager) getsystemservice ( Context.connectivity_service);//Show only active connections Networkinfo info = cm.getactivenetworkinfo (); if (info! = null) { Netinfoshow.settext (Info.tostring ());} Show all connections networkinfo[] infos = Cm.getallnetworkinfo (), if (infos! = null) {StringBuilder SB = new StringBuilder ("All:"); (int i = 0; i < infos.length; i++) {sb.append (infos[i]+ "\ n");} Netinfoshows.settext (Sb.tostring ());}}}
To maximize battery life:
(1) Background data settings:
The user can specify in the settings whether to allow background data transfer.
(2) Frequency of data transmission:
If you can control the transmission type of the data, you can compress the data before transferring it to the device. The usual procedure is:
1. Use gzip to compress text data and use the Gzipinputstream class to access data
2. If possible, use JPEG instead of PNG format image file
3. Use a resource that matches the resolution of the device (for example, you do not have to download 1920x1080 images for a 96x54 size display space).
Extend battery life-the impact of network data