簡體   English   中英

Android WifiManager-十六進制或不十六進制

[英]Android WifiManager - to HEX or not to HEX

我試圖以編程方式使用Android連接到wifi,但是當我在Hex中輸入我的WEP密鑰時-Logcat指出它太長了。 當我嘗試使用純文本時,它表示它太短了(並且從不連接)。 當我在自己構建的應用程序外部手動輸入(只需輸入密碼:超人)時,它就會連接!

聚苯乙烯

我正在嘗試使用以下StackOverflow示例:

如何以編程方式連接到Android中的特定Wi-Fi網絡?

帶十六進制:

    String networkSSID = "ANDRE-PC_NETWORK";
    String networkPass = "73:75:70:65:72:6d:61:6e";

LOGCAT:

04-04 12:12:13.643: E/wpa_supplicant(594): Line 0: Too long WEP key 0 '"73:75:70:65:72:6d:61:6e"'.
04-04 12:12:13.643: E/WifiConfigStore(479): failed to set wep_key0: "73:75:70:65:72:6d:61:6e"
04-04 12:12:13.793: I/ActivityManager(479): Displayed com.nfc.linked/.Connect: +855ms
04-04 12:12:16.283: W/GAV2(3422): Thread[Service Reconnect,5,main]: Connection to service failed 1

沒有十六進制:

  String networkSSID = "ANDRE-PC_NETWORK";
  String networkPass = "superman";

LOGCAT:

04-04 12:23:10.913: E/wpa_supplicant(594): Line 0: Invalid WEP key length 8 - this network block will be ignored

資源:

import java.util.List;

import android.app.Activity;    
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.util.Log;
import android.content.Context; 

public class Connect extends Activity  {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.connect);
        String networkSSID = "ANDRE-PC_NETWORK";
        String networkPass = "superman";

        WifiConfiguration conf = new WifiConfiguration();
        conf.SSID = "\"" + networkSSID + "\"";   //ssid must be in quotes


        conf.wepKeys[0] = "\"" + networkPass + "\""; 
        conf.wepTxKeyIndex = 0;
        conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
       conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40); 

        conf.preSharedKey = "\""+ networkPass +"\"";

        conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);

        WifiManager wifiManager = (WifiManager)getSystemService(WIFI_SERVICE); 
        wifiManager.addNetwork(conf);

        List<WifiConfiguration> list = wifiManager.getConfiguredNetworks();
        for( WifiConfiguration i : list ) {
            if(i.SSID != null && i.SSID.equals("\"" + networkSSID + "\"")) {
                 wifiManager.disconnect();
                 wifiManager.enableNetwork(i.networkId, true);
                 wifiManager.reconnect();                

                 break;
            }           
         }

    }}

嘗試:

String networkPass = "73757065726d616e";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM