Android設備通常的多個數據連接:
(1)Bluetooth
(2)Ethernet
(3)WI-FI
(4)WiMax
(5)移動網絡(EDGE,UMTS,LTE)
獲取網絡信息:
public class NetInfo extends Activity {
private TextView netInfoShow,netInfoShows;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.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);
//只顯示活動的連接
NetworkInfo info = cm.getActiveNetworkInfo();
if (info != null) {
netInfoShow.setText(info.toString());
}
//顯示所有連接
NetworkInfo[] infos = cm.getAllNetworkInfo();
if (infos != null) {
StringBuilder sb = new StringBuilder("All: ");
for (int i = 0; i < infos.length; i++) {
sb.append(infos[i]+"\n");
}
netInfoShows.setText(sb.toString());
}
}
}
(1)後臺數據設置:
用戶可以在設置中指定是否允許後臺數據傳輸。。
(2)數據傳輸頻度:
如果能控制數據的傳輸類型,就可以先壓縮數據,在傳輸到設備上。通常做法爲:
1.使用GZIP壓縮文本數據,使用GZIPInputStream類訪問數據
2.如果可能的話使用JPEG而不是PNG格式的圖像文件
3.使用匹配設備分辨率的資源(比如,不必爲96x54大小的顯示空間下載1920x1080的圖片)。