当wifi打开时,仅通过Android手机上的移动数据发送数据 [英] Send data only through mobile data on android phones when wifi is on

查看:35
本文介绍了当wifi打开时,仅通过Android手机上的移动数据发送数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过移动数据以编程方式路由请求,即使 wifi 已打开并连接到互联网?

Is it possible to programmatically route a request through mobile data even when the wifi is on and connected to the internet?

我的应用需要调用运营商提供的服务,该服务只能通过移动数据使用,我认为要求关闭 wifi 对用户不友好.

My app needs to call a service provided by the operator which is only available through mobile data and I don't think it's user-friendly to ask for turning off the wifi.

推荐答案

看看 https://developer.android.com/reference/android/net/ConnectivityManager.html

特别是,它有一个功能可以让你做你想做的事.

specifically, it has a function that allows you to do what you want.

 5 Provide an API that allows applications to request and select networks for their data traffic

你请求一个网络,然后 setDefaultNetwork(API before 23) 或者使用 bindProcessToNetwork for API >= 23 .

you request a network, and then setDefaultNetwork( API before 23) or use bindProcessToNetwork for API >= 23 .

您可能想要请求具有 int TRANSPORT_CELLULAR 功能的网络(https://developer.android.com/reference/android/net/NetworkCapabilities.html)

you probably want to request a network with int TRANSPORT_CELLULAR capabilities (https://developer.android.com/reference/android/net/NetworkCapabilities.html)

这篇关于当wifi打开时,仅通过Android手机上的移动数据发送数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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