當前位置:首頁 » 安卓系統 » android連接指定的wifi

android連接指定的wifi

發布時間: 2024-08-22 02:09:25

❶ Android如何添加隱藏的無線wifi配置文件

1、打開 設定 頁面,點擊 Wi-Fi


2、點擊 添加WLAN網路


3、手動輸入路由器的SSID、無線密碼等參數,點擊 儲存,保存無線配置文件



4、無線配置文件添加完成,無線信號顯示已連接


注意:添加了無線配置文件,手機重啟後(或手機從外面拿回家)會自動連接路由器的無線信號,不需要重新添加無線配置文件。

❷ android怎麼自動連接以zd開頭的wifi,知道密碼,想用代碼直接連接

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 }
// 構造函數 public WifiAutoConnectManager(WifiManager wifiManager) { this.wifiManager = wifiManager; }
// 提供一個外部介面,傳入要連接的無線網 public void connect(String ssid, String password, WifiCipherType type) { Thread thread = new Thread(new ConnectRunnable(ssid, password, type)); thread.start(); }
// 查看以前是否也配置過這個網路 private WifiConfiguration isExsits(String SSID) { List<WifiConfiguration> 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); // 此處需要修改否則不能自動重聯 // 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功能需要一段時間(我在手機上測試一般需要1-3秒左右),所以要等到wifi // 狀態變成WIFI_STATE_ENABLED的時候才能執行下面的語句 while (wifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLING) { try { // 為了避免程序一直while循環,讓它睡個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; }}

❸ Android手機如何設置wifi設備名

1、首先打開手機設置,點擊選擇「其他無線連接」按鈕。

❹ android wifi 開發中 如何判斷成功連接上了指定的wifi熱點

首先通過WifiManager對象獲取系統服務的WIFI_SERVICE,然後調用getConnectionInfo()獲得WifiInfo對象,再通過WifiInfo對象獲取已連上wifi的SSID(實際上是housyunhin說的WifiInfo.getSSID()和其他wifi信息),之後判斷是否匹配即可

❺ android 命令怎麼連接wifi點

1234567891011121314151617/** * 檢測網路是否連接 * @return */ private boolean checkNetworkState() { boolean flag = false; //得到網路連接信息 manager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); //去進行判斷網路是否連接 if (manager.getActiveNetworkInfo() != null) { flag = manager.getActiveNetworkInfo().isAvailable(); } if (!flag) { setNetwork(); } else { isNetworkAvailable(); }12 return flag; } /** * 網路未連接時,調用設置方法 */ private void setNetwork(){ Toast.makeText(this, "wifi is closed!", Toast.LENGTH_SHORT).show(); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setIcon(R.drawable.ic_launcher); builder.setTitle("網路提示信息"); builder.setMessage("網路不可用,如果繼續,請先設置網路!"); builder.setPositiveButton("設置", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent intent = null; /** * 判斷手機系統的版本!如果<a href="https:///s?wd=API&tn=44039180_cpr&fenlei=-EUBt1njRLPWfkn1D4PWm1njmkPWf" target="_blank" class="-highlight">API</a>大於10 就是3.0+ * 因為3.0以上的版本的設置和3.0以下的設置不一樣,調用的方法不同 */ if (android.os.Build.VERSION.SDK_INT > 10) { intent = new Intent(android.provider.Settings.ACTION_WIFI_SETTINGS); } else { intent = new Intent(); ComponentName component = new ComponentName( "com.android.settings", "com.android.settings.WirelessSettings"); intent.setComponent(component); intent.setAction("android.intent.action.VIEW"); } startActivity(intent); } });123 builder.setNegativeButton("取消", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) {3233343536 } }); builder.create(); builder.show(); } /** * 網路已經連接,然後去判斷是wifi連接還是<a href="https:///s?wd=GPRS&tn=44039180_cpr&fenlei=-EUBt1njRLPWfkn1D4PWm1njmkPWf" target="_blank" class="-highlight">GPRS</a>連接 * 設置一些自己的邏輯調用 */ private void isNetworkAvailable(){ State <a href="https:///s?wd=gprs&tn=44039180_cpr&fenlei=-EUBt1njRLPWfkn1D4PWm1njmkPWf" target="_blank" class="-highlight">gprs</a> = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState(); State wifi = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState(); if(<a href="https:///s?wd=gprs&tn=44039180_cpr&fenlei=-EUBt1njRLPWfkn1D4PWm1njmkPWf" target="_blank" class="-highlight">gprs</a> == State.CONNECTED gprs == State.CONNECTING){ Toast.makeText(this, "wifi is open! gprs", Toast.LENGTH_SHORT).show(); } //判斷為wifi狀態下才載入廣告,如果是GPRS手機網路則不載入! if(wifi == State.CONNECTED wifi == State.CONNECTING){ Toast.makeText(this, "wifi is open! wifi", Toast.LENGTH_SHORT).show(); loadAdmob(); } } /** * 在wifi狀態下 載入admob廣告 */ private void loadAdmob(){ ll = (LinearLayout) findViewById(R.id.load_ads); ll.removeAllViews(); adsView = new AdView(this, AdSize.BANNER, "a15194a1ac9505d"); ll.addView(adsView); adsView.loadAd(new AdRequest()); }

熱點內容
手游伺服器怎麼找ip 發布:2024-11-25 08:23:10 瀏覽:751
c語言名次 發布:2024-11-25 08:04:22 瀏覽:55
新浪雲伺服器登錄 發布:2024-11-25 08:04:21 瀏覽:853
工控機伺服器電腦的區別 發布:2024-11-25 08:04:21 瀏覽:513
Python對比matlab 發布:2024-11-25 07:45:58 瀏覽:307
ovt機頂盒管理員密碼多少 發布:2024-11-25 07:45:58 瀏覽:377
win10與linux雙系統 發布:2024-11-25 07:40:05 瀏覽:658
網易我的世界4d皮膚伺服器 發布:2024-11-25 07:38:36 瀏覽:944
傳奇結義腳本 發布:2024-11-25 07:31:25 瀏覽:662
linuxpppd 發布:2024-11-25 07:29:54 瀏覽:294