真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

androidwifi開發(fā),android wifi連接

Android的WiFi功能總結(jié)

先進(jìn)行WiFi權(quán)限的聲明

成都創(chuàng)新互聯(lián)公司是一家企業(yè)級云計算解決方案提供商,超15年IDC數(shù)據(jù)中心運營經(jīng)驗。主營GPU顯卡服務(wù)器,站群服務(wù)器,成都聯(lián)通服務(wù)器托管,海外高防服務(wù)器,大帶寬服務(wù)器,動態(tài)撥號VPS,海外云手機(jī),海外云服務(wù)器,海外服務(wù)器租用托管等。

!-- 獲取WiFi狀態(tài) --

uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /

uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /

!--? api = Android29調(diào)用setWifiEnabled??--

uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /

!-- 定位權(quán)限(api = 23 用于 WIFI掃描)--

uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /

uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /

注意:ACCESS_FINE_LOCATION和ACCESS_COARSE_LOCATION是危險級權(quán)限需要使用中還需要動態(tài)申請,申請其中一個即可。

WifiManager mWifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);

if (Build.VERSION.SDK_INT =Build.VERSION_CODES.R) {

Intent panelIntent =new Intent(Settings.Panel.ACTION_WIFI);

startActivityForResult(panelIntent,null);

}else{ mWifiManager.setWifiEnabled(!isEnable);}

可以通過監(jiān)聽系統(tǒng)廣播來了解WiFi狀態(tài)。

WIFI_STATE_CHANGED_ACTION:WiFi開關(guān)狀態(tài);

SCAN_RESULTS_AVAILABLE_ACTION:WiFi列表變化;

RSSI_CHANGED_ACTION:WiFi信號強度變化。

IntentFilter mFilter =new IntentFilter();

mFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);

mFilter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);

mFilter.addAction(WifiManager.RSSI_CHANGED_ACTION);

mReceiver =new BroadcastReceiver() {

@Override

public void onReceive(Context context,Intent intent) {

handleEvent(intent);

}

};

registerReceiver(mReceiver, mFilter);

private void handleEvent(Intent intent) {

String action = intent.getAction();

if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)) {

final int wifiState =mWifiManager.getWifiState();

if(wifiState ==WifiManager.WIFI_STATE_ENABLED){

postDelayed(()-{mRefreshLayout.autoRefresh();},1000);

}

}else if (WifiManager.SCAN_RESULTS_AVAILABLE_ACTION.equals(action)) {

}else if (WifiManager.RSSI_CHANGED_ACTION.equals(action)) {

if(System.currentTimeMillis() -mLastUpateWifiRssiTime 1000){//刷新太快

? ? ? ? return;

}

}

updateWifiChange();

}

切記:wifistate切換到WifiManager.WIFI_STATE_ENABLED,mWifiManager.isWifiEnabled()需要有個等待時間切換。

3的基礎(chǔ)上解析廣播應(yīng)答

private void updateWifiChange() {

final int wifiState =mWifiManager.getWifiState();

switch (wifiState) {

case WifiManager.WIFI_STATE_ENABLED:

ArrayListresults = (ArrayList)mWifiManager.getScanResults();

updateApListView(results);

mWlanSb.setChecked(mWifiManager.isWifiEnabled() );

break;

case WifiManager.WIFI_STATE_ENABLING:

break;

case WifiManager.WIFI_STATE_DISABLING:

mAdapter.clearData();

mWlanSb.setChecked(mWifiManager.isWifiEnabled() );

break;

case WifiManager.WIFI_STATE_DISABLED:

break;

}

}

android如何開發(fā)手動連接隱藏的wifi

您好,連接隱藏wifi的方法:

1、打開設(shè)置,進(jìn)入WIFI開關(guān)界面

2、點擊WIFI鏈接,選擇要鏈接的WIFI.

3、選擇下面的其他鏈接方式。

4、輸入隱藏的WIFI名稱,就是路由器發(fā)出來信號的名字。

5、點擊安全性選擇加密方式,一般加密方式都是WPA/WPA2PSK。

6、輸入WIFI的密碼,點擊確定即可連接該wifi網(wǎng)絡(luò)了。

Android WiFi開發(fā),如何自動連接的代碼

public class WifiAutoConnectManager {

private static final String TAG = WifiAutoConnectManager.class.getSimpleName();

WifiManager wifiManager;

// 定義幾種加密方式,一種是WEP,一種是WPA,還有沒有密碼的情況 public enum WifiCipherType { WIFICIPHER_WEP, WIFICIPHER_WPA, WIFICIPHER_NOPASS, WIFICIPHER_INVALID }

// 構(gòu)造函數(shù) public WifiAutoConnectManager(WifiManager wifiManager) { this.wifiManager = wifiManager; }

// 提供一個外部接口,傳入要連接的無線網(wǎng) public void connect(String ssid, String password, WifiCipherType type) { Thread thread = new Thread(new ConnectRunnable(ssid, password, type)); thread.start(); }

// 查看以前是否也配置過這個網(wǎng)絡(luò) private WifiConfiguration isExsits(String SSID) { ListWifiConfiguration existingConfigs = wifiManager.getConfiguredNetworks(); for (WifiConfiguration existingConfig : existingConfigs) { if (existingConfig.SSID.equals("\"" + SSID + "\"")) { return existingConfig; } } return null; }

private WifiConfiguration createWifiInfo(String SSID, String Password, WifiCipherType Type) { WifiConfiguration config = new WifiConfiguration(); config.allowedAuthAlgorithms.clear(); config.allowedGroupCiphers.clear(); config.allowedKeyManagement.clear(); config.allowedPairwiseCiphers.clear(); config.allowedProtocols.clear(); config.SSID = "\"" + SSID + "\""; // nopass if (Type == WifiCipherType.WIFICIPHER_NOPASS) { config.wepKeys[0] = ""; config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); config.wepTxKeyIndex = 0; } // wep if (Type == WifiCipherType.WIFICIPHER_WEP) { if (!TextUtils.isEmpty(Password)) { if (isHexWepKey(Password)) { config.wepKeys[0] = Password; } else { config.wepKeys[0] = "\"" + Password + "\""; } } config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN); config.allowedAuthAlgorithms.set(AuthAlgorithm.SHARED); config.allowedKeyManagement.set(KeyMgmt.NONE); config.wepTxKeyIndex = 0; } // wpa if (Type == WifiCipherType.WIFICIPHER_WPA) { config.preSharedKey = "\"" + Password + "\""; config.hiddenSSID = true; config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN); config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK); config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP); // 此處需要修改否則不能自動重聯(lián) // config.allowedProtocols.set(WifiConfiguration.Protocol.WPA); config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP); config.status = WifiConfiguration.Status.ENABLED; } return config; }

// 打開wifi功能 private boolean openWifi() { boolean bRet = true; if (!wifiManager.isWifiEnabled()) { bRet = wifiManager.setWifiEnabled(true); } return bRet; }

class ConnectRunnable implements Runnable { private String ssid;

private String password;

private WifiCipherType type;

public ConnectRunnable(String ssid, String password, WifiCipherType type) { this.ssid = ssid; this.password = password; this.type = type; }

@Override public void run() { // 打開wifi openWifi(); // 開啟wifi功能需要一段時間(我在手機(jī)上測試一般需要1-3秒左右),所以要等到wifi // 狀態(tài)變成WIFI_STATE_ENABLED的時候才能執(zhí)行下面的語句 while (wifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLING) { try { // 為了避免程序一直while循環(huán),讓它睡個100毫秒檢測…… Thread.sleep(100); } catch (InterruptedException ie) { } }

WifiConfiguration wifiConfig = createWifiInfo(ssid, password, type); // if (wifiConfig == null) { Log.d(TAG, "wifiConfig is null!"); return; }

WifiConfiguration tempConfig = isExsits(ssid);

if (tempConfig != null) { wifiManager.removeNetwork(tempConfig.networkId); }

int netID = wifiManager.addNetwork(wifiConfig); boolean enabled = wifiManager.enableNetwork(netID, true); Log.d(TAG, "enableNetwork status enable=" + enabled); boolean connected = wifiManager.reconnect(); Log.d(TAG, "enableNetwork connected=" + connected); } }

private static boolean isHexWepKey(String wepKey) { final int len = wepKey.length();

// WEP-40, WEP-104, and some vendors using 256-bit WEP (WEP-232?) if (len != 10 len != 26 len != 58) { return false; }

return isHex(wepKey); }

private static boolean isHex(String key) { for (int i = key.length() - 1; i = 0; i--) { final char c = key.charAt(i); if (!(c = '0' c = '9' || c = 'A' c = 'F' || c = 'a' c = 'f')) { return false; } }

return true; }}

使用wifi要添加什么權(quán)限 Android開發(fā)

ACCESS_WIFI_STATE權(quán)限可以獲取使用Wi-Fi等WLAN無線網(wǎng)絡(luò),加入android.permission.ACCESS_WIFI_STATE這句.

CHANGE_WIFI_STATE是改變WLAN狀態(tài)的開關(guān),如果打開或關(guān)閉Wi-Fi必需加入android.permission.CHANGE_WIFI_STATE的聲明.

[img]

Android開發(fā)如何使用代碼配置手機(jī)wifi的pac地址?

這里用到的手機(jī)型號為魅族M6120,其中的具體步驟如下:

1、打開手機(jī)的設(shè)置界面,需要選擇無線網(wǎng)絡(luò)這一項。

2、在無線網(wǎng)絡(luò)中找到已經(jīng)連接的WIFI網(wǎng)絡(luò),并點擊旁邊的詳情按鈕。

3、會進(jìn)入WIFI的詳情頁面,選擇底部的代理設(shè)置項目。

4、等來到代理設(shè)置窗口以后,點擊里面的無選項。

5、下一步,在菜單中選擇手動這一項。

6、這個時候可以填寫相關(guān)的服務(wù)器和端口。

7、這樣一來通過點擊右上角的保存按鈕,即可實現(xiàn)Android開發(fā)使用代碼配置手機(jī)wifi的pac地址。


名稱欄目:androidwifi開發(fā),android wifi連接
本文網(wǎng)址:http://weahome.cn/article/dsohojp.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部