连接到离线 Wi-Fi 并继续使用移动数据(也适用于所有其他应用) [英] Connect to an offline Wi-Fi and keep using mobile data (for all other apps, too)

查看:51
本文介绍了连接到离线 Wi-Fi 并继续使用移动数据(也适用于所有其他应用)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序需要通过 Wi-Fi 连接到硬件.为此,硬件提供了一个离线 Wi-Fi 热点.热点的 DHCP 没有为我们提供网关或 DNS,所以我们马上就知道它仅供离线使用.

最终用户将在工作,并且必须始终保持与 Wi-Fi 的连接,以便接收传感器数据并在数据出现问题时发出警报.但与此同时,我们不想强迫最终用户使用他的移动设备离线.他应该能够将他的移动数据用于我们和他拥有的所有其他应用.

我虽然可以通过调用

解决方案

在各种设备上尝试了这个之后,我可以说,不可能在所有设备上一致地实现所需的行为.几乎所有设备的行为都不同.操作系统版本并不是一个真正的因素.这更多地取决于供应商如何处理这种情况,即用户连接到离线 wifi.

根据设备,可能可以保持连接到离线 wifi 并同时为所有应用使用移动数据.但是操作系统可以自动断开您的连接或将您锁定在离线 wifi 中并禁用移动数据.可能是因为用户在系统对话框中选择了一个选项,如上所示.

在后一种情况下,可以使用 ConnectivityManager自己的应用程序 强制建立移动数据连接.但不可能让所有其他应用也使用此移动连接.

I have an app that needs to connect to a hardware via Wi-Fi. For this purpose, the hardware offers an offline Wi-Fi Hotspot. The hotspot's DHCP doesn't give us a gateway or DNS so we know right away, that it's for offline use only.

The end user will be at work and have to stay connected to the Wi-Fi the whole time in order to receive sensor data and alerts if something is wrong with the data. But at the same time, we don't want to force the end user to be offline with his mobile device. He should be able to use his mobile data for our and all other apps he has.

I though I can control this by calling android.net.ConnectivityManager.requestNetwork. But it doesn't seem to work reliably. Will calling requestNetwork in my app influence if all the other apps have access to mobile data?

Is this even something that we can control? I tested this on multiple devices with different manufacturers and android versions and they all behave differently.

E.g. Pixel 3a works fine. After some time I get a notification regarding the offline Wi-Fi. If I ignore it, it keeps working. If I press "yes" on it, I am offline and connected to the Wi-Fi.

Huawei P20 Lite seems to fire a OnLost event for my mobile data NetworkCallback every time I request it. Like its trying to cancel the mobile connection every time I reconnect because I'm in the wifi. Some devices offer a "Smart Switch" (Samsung) or "Wi-Fi+" (Huawei) mode which isn't on per default. And it seems like a hassle to ask the user to turn it on, since they might not want to use it in different scenarios.

Here are some examples for the different devices:

解决方案

After trying this out on various devices, I can say, that it is not possible to achive the desired behaviour consinstently on all devices. Pretty much all the devices, behave differently. The OS-version is not really a factor. It depends more on how the vendors handle the case, that a user is connected to an offline wifi.

Based on the device, it might be possible to stay connected to offline wifi and use mobile data at the same time for all apps. But the OS can automatically disconnect you or lock you into the offline-wifi and disable mobile data. Maybe it does it because the user selected an option in the system dialogs as shown above.

In the latter case, it is possible to force a mobile data connection with the ConnectivityManager for the own app. But it is not possible to make all the other apps use this mobile connection as well.

这篇关于连接到离线 Wi-Fi 并继续使用移动数据(也适用于所有其他应用)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆