Android 以编程方式连接到wifi在新API上不起作用
我想以编程方式连接Wifi。我在我的旧设备(4年前买的)上做了一些测试,它工作得非常好。然而,当我在我的模拟器(android 8.1.0,API 27)上做一些测试时,它并没有工作。你有什么解释吗?(实际上,我可以在保存的设置网络上看到我的wifi,但设备未连接到wifi) 这是我的代码(我基本上是从堆栈溢出问题的答案中复制的:): 以下是日志:Android 以编程方式连接到wifi在新API上不起作用,android,wifimanager,wifi,Android,Wifimanager,Wifi,我想以编程方式连接Wifi。我在我的旧设备(4年前买的)上做了一些测试,它工作得非常好。然而,当我在我的模拟器(android 8.1.0,API 27)上做一些测试时,它并没有工作。你有什么解释吗?(实际上,我可以在保存的设置网络上看到我的wifi,但设备未连接到wifi) 这是我的代码(我基本上是从堆栈溢出问题的答案中复制的:): 以下是日志: 09-04 09:16:34.348 7410-8091/amiin.bazouk.application.com.localisationdemo
09-04 09:16:34.348 7410-8091/amiin.bazouk.application.com.localisationdemo V/rht: Configuring WPA
09-04 09:16:34.352 1725-2739/system_process I/WifiService: addOrUpdateNetwork uid=10079
09-04 09:16:34.352 1725-2739/system_process I/addOrUpdateNetwork: uid = 10079 SSID "partner" nid=-1
09-04 09:16:34.357 1725-2497/system_process I/WifiService: getConfiguredNetworks uid=10014
09-04 09:16:34.377 1725-2041/system_process D/WifiConfigStore: Writing to stores completed in 21 ms.
09-04 09:16:34.381 1725-2497/system_process I/WifiService: disconnect uid=10079
09-04 09:16:34.383 7831-7831/? E/wpa_supplicant: nl80211: Failed to open /proc/sys/net/ipv4/conf/wlan0/drop_unicast_in_l2_multicast: No such file or directory
nl80211: Failed to set IPv4 unicast in multicast filter
09-04 09:16:34.384 1725-2497/system_process I/WifiService: enableNetwork uid=10079 disableOthers=true
09-04 09:16:34.391 1397-3075/? W/audio_hw_generic: Hardware backing HAL too slow, could only write 0 of 720 frames
09-04 09:16:34.393 1725-2041/system_process D/WifiStateMachine: connectToUserSelectNetwork netId 8, uid 10079, forceReconnect = false
09-04 09:16:34.396 1725-2739/system_process I/WifiService: getConfiguredNetworks uid=10014
09-04 09:16:34.405 1397-3075/? W/audio_hw_generic: Hardware backing HAL too slow, could only write 0 of 720 frames
09-04 09:16:34.421 1397-3075/? W/audio_hw_generic: Hardware backing HAL too slow, could only write 0 of 720 frames
09-04 09:16:34.439 1725-2041/system_process D/WifiConfigStore: Writing to stores completed in 27 ms.
09-04 09:16:34.439 1725-2041/system_process E/WifiConfigManager: UID 10079 does not have permission to update configuration "partner"WPA_PSK
09-04 09:16:34.439 1725-2041/system_process I/WifiStateMachine: connectToUserSelectNetwork Allowing uid 10079 with insufficient permissions to connect=8
09-04 09:16:34.440 1725-2041/system_process D/WifiStateMachine: CMD_START_CONNECT sup state DisconnectedState my state DisconnectedState nid=8 roam=false
09-04 09:16:34.443 1725-2497/system_process I/WifiService: reconnect uid=10079
09-04 09:16:34.446 1562-1562/? E/wificond: Received error messsage: Operation not supported on transport endpoint
NL80211_CMD_ABORT_SCAN failed
09-04 09:16:34.446 1562-1562/? W/wificond: Abort scan failed
09-04 09:16:34.447 1725-2041/system_process D/SupplicantStaIfaceHal: connectToNetwork "partner"WPA_PSK
Network is already saved, will not trigger remove and add operation.
09-04 09:16:34.699 1725-2497/system_process D/WificondControl: Scan result ready event
09-04 09:16:34.715 1725-2041/system_process W/WifiConfigManager: Looking up network with invalid networkId -1
- 设置
conf.BSSID
- 在
和conf.SSID
之前和之后添加双引号(“)conf.preSharedKey
09-04 09:16:34.348 7410-8091/amiin.bazouk.application.com.localisationdemo V/rht: Configuring WPA
09-04 09:16:34.352 1725-2739/system_process I/WifiService: addOrUpdateNetwork uid=10079
09-04 09:16:34.352 1725-2739/system_process I/addOrUpdateNetwork: uid = 10079 SSID "partner" nid=-1
09-04 09:16:34.357 1725-2497/system_process I/WifiService: getConfiguredNetworks uid=10014
09-04 09:16:34.377 1725-2041/system_process D/WifiConfigStore: Writing to stores completed in 21 ms.
09-04 09:16:34.381 1725-2497/system_process I/WifiService: disconnect uid=10079
09-04 09:16:34.383 7831-7831/? E/wpa_supplicant: nl80211: Failed to open /proc/sys/net/ipv4/conf/wlan0/drop_unicast_in_l2_multicast: No such file or directory
nl80211: Failed to set IPv4 unicast in multicast filter
09-04 09:16:34.384 1725-2497/system_process I/WifiService: enableNetwork uid=10079 disableOthers=true
09-04 09:16:34.391 1397-3075/? W/audio_hw_generic: Hardware backing HAL too slow, could only write 0 of 720 frames
09-04 09:16:34.393 1725-2041/system_process D/WifiStateMachine: connectToUserSelectNetwork netId 8, uid 10079, forceReconnect = false
09-04 09:16:34.396 1725-2739/system_process I/WifiService: getConfiguredNetworks uid=10014
09-04 09:16:34.405 1397-3075/? W/audio_hw_generic: Hardware backing HAL too slow, could only write 0 of 720 frames
09-04 09:16:34.421 1397-3075/? W/audio_hw_generic: Hardware backing HAL too slow, could only write 0 of 720 frames
09-04 09:16:34.439 1725-2041/system_process D/WifiConfigStore: Writing to stores completed in 27 ms.
09-04 09:16:34.439 1725-2041/system_process E/WifiConfigManager: UID 10079 does not have permission to update configuration "partner"WPA_PSK
09-04 09:16:34.439 1725-2041/system_process I/WifiStateMachine: connectToUserSelectNetwork Allowing uid 10079 with insufficient permissions to connect=8
09-04 09:16:34.440 1725-2041/system_process D/WifiStateMachine: CMD_START_CONNECT sup state DisconnectedState my state DisconnectedState nid=8 roam=false
09-04 09:16:34.443 1725-2497/system_process I/WifiService: reconnect uid=10079
09-04 09:16:34.446 1562-1562/? E/wificond: Received error messsage: Operation not supported on transport endpoint
NL80211_CMD_ABORT_SCAN failed
09-04 09:16:34.446 1562-1562/? W/wificond: Abort scan failed
09-04 09:16:34.447 1725-2041/system_process D/SupplicantStaIfaceHal: connectToNetwork "partner"WPA_PSK
Network is already saved, will not trigger remove and add operation.
09-04 09:16:34.699 1725-2497/system_process D/WificondControl: Scan result ready event
09-04 09:16:34.715 1725-2041/system_process W/WifiConfigManager: Looking up network with invalid networkId -1