編輯:關於Android編程
做網絡診斷,需要診斷當前wifi所在信道是否擁擠,目前只是解決了獲取當前wifi所在信道,主要是用ScanResult 的frequency字段,還需要用SSID和BSSID從ScanResults匹配到當前的wifi信號wifiInfo,具體代碼如下:
public static int getCurrentChannel(Context context) { WifiManager wifiManager = (WifiManager) context .getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo();// 當前wifi連接信息 ListscanResults = wifiManager.getScanResults(); for (ScanResult result : scanResults) { if (result.BSSID.equalsIgnoreCase(wifiInfo.getBSSID()) && result.SSID.equalsIgnoreCase(wifiInfo.getSSID() .substring(1, wifiInfo.getSSID().length() - 1))) { return getChannelByFrequency(result.frequency); } } return -1; } /** * 根據頻率獲得信道 * * @param frequency * @return */ public static int getChannelByFrequency(int frequency) { int channel = -1; switch (frequency) { case 2412: channel = 1; break; case 2417: channel = 2; break; case 2422: channel = 3; break; case 2427: channel = 4; break; case 2432: channel = 5; break; case 2437: channel = 6; break; case 2442: channel = 7; break; case 2447: channel = 8; break; case 2452: channel = 9; break; case 2457: channel = 10; break; case 2462: channel = 11; break; case 2467: channel = 12; break; case 2472: channel = 13; break; case 2484: channel = 14; break; case 5745: channel = 149; break; case 5765: channel = 153; break; case 5785: channel = 157; break; case 5805: channel = 161; break; case 5825: channel = 165; break; } return channel; }
平時用到也就那麼幾個方法,花費了時間學的東西用的少就忘記了,撿一撿是時候做做記錄了.為了以後復習起來也方便json是一種格式,用來交換文本形式數據.解析json的方式也有
Android中的TextView控件默認是做不到兩端對齊的,都是左對齊。可能的原因是安卓默認數字、字母不能為第一行以後每行的開頭字符,因為數字、字母為半角字符,還有就是
環境主機:WIN 7開發環境:Android Studio2.2.2步驟安裝NDK打開Tools->Android->SDK Manager->SDK
在使用eclipse進行安卓java的編程的時候,有時候我們會遇到這樣的問題:那就是無故彈出aapt.exe停止工作的提示,雖然程序不會崩潰,但是這個提示經常彈出很是煩人