Android-强制网络请求通过wifi而不是移动网络 [英] Android - force network requests go through wifi instead of mobile network

查看:649
本文介绍了Android-强制网络请求通过wifi而不是移动网络的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个连接到硬件设备Wi-Fi热点的应用. 似乎Android会通过其他网络(例如3G/4G)转发请求,而不是通过热点转发,因为我的热点没有互联网连接.

I have an app which connects to a hardware device Wi-Fi hotspot. It seems that Android forward requests over other networks (3G/4G for example) instead the hotspot, since my hot spot has no internet connection.

有什么方法可以强制网络流在wifi上工作? 我遇到了以下功能,但已弃用: https://developer.android.com/reference/android/net/ConnectivityManager.html#setNetworkPreference(int)

Is there any way to force network stream to work on the wifi? I've come across the following function, but it's deprecated: https://developer.android.com/reference/android/net/ConnectivityManager.html#setNetworkPreference(int)

推荐答案

每个

要将所有网络请求从您的应用程序定向到外部Wi-Fi设备,请调用

To direct all the network requests from your app to an external Wi-Fi device, call ConnectivityManager#setProcessDefaultNetwork on Lollipop devices, and on Marshmallow call ConnectivityManager#bindProcessToNetwork instead, which is a direct API replacement.

这篇关于Android-强制网络请求通过wifi而不是移动网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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