Android WifiManager - 以十六进制或不以十六进制
我试图用编程方式连接到使用Android的wifi,但是当我输入我的WEP密钥在十六进制 - Logcat状态它太长。当我尝试使用明文时 - 它表明它太短(并且从不连接)。当我在我创建的应用程序外部手动输入时(通过简单地输入密码:超人),它会连接!Android WifiManager - 以十六进制或不以十六进制
P.S.
我尝试使用下面的StackOverflow例如:
How do I connect to a specific Wi-Fi network in Android programmatically?
六角:
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";
以上是 Android WifiManager - 以十六进制或不以十六进制 的全部内容, 来源链接: utcz.com/qa/267312.html