2017-07-19 104 views
2

即使无线网络连接并连接到互联网,是否可以通过移动数据以编程方式发送请求?仅当wifi上的数据通过手机数据发送数据时

我的应用程序需要调用运营商提供的服务,该服务只能通过移动数据获得,并且我不认为用户要求关闭wifi是不方便的。

回答

1

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

具体而言,它有一个功能,可以让你做你想要的。

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

你请求网络,然后setDefaultNetwork(API 23之前),或者使用用于bindProcessToNetwork API> = 23。

你可能想请求一个int int TRANSPORT_CELLULAR功能的网络(https://developer.android.com/reference/android/net/NetworkCapabilities.html