Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/212.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 以编程方式连接到wifi在新API上不起作用_Android_Wifimanager_Wifi - Fatal编程技术网

Android 以编程方式连接到wifi在新API上不起作用

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

我想以编程方式连接Wifi。我在我的旧设备(4年前买的)上做了一些测试,它工作得非常好。然而,当我在我的模拟器(android 8.1.0,API 27)上做一些测试时,它并没有工作。你有什么解释吗?(实际上,我可以在保存的设置网络上看到我的wifi,但设备未连接到wifi) 这是我的代码(我基本上是从堆栈溢出问题的答案中复制的:):

以下是日志:

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
    之前和之后添加双引号(“)

Android 8.1+将不会直接连接到wifi首先在运行时为COURSE_LOCATION添加权限,然后它将连接

您可以发布日志吗?您应该尝试在真实设备上测试代码。正如您在日志中看到的,emulator无法检测ipv4设置,并且日志告诉您该操作不受支持。因此,您的code没问题,但你需要在真正的设备上进行测试,以检查它是否真的工作。@Maxouille我已经发布了日志。@Umair我最近没有设备,很遗憾……这就是为什么我尝试使用模拟器的原因……但我的朋友(离我很远)告诉我,它在他的新设备上不工作
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