如何以编程方式禁用移动数据为我的应用程序只 [英] How to disable mobile data programmatically for my app only

查看:153
本文介绍了如何以编程方式禁用移动数据为我的应用程序只的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个应用程序,我担心以数据的用户可以彼此之间转帐的金额。由于一些用户具有有限的移动数据计划,有的没有,我想知道如果我能制定一个开关来为我的特定应用禁用移动数据。
喜欢什么Android的自身的数据使用的位 - >手机 - >程序 - >限制后台数据不...

I am developing an app, and I'm concerned as to the amount of data users can transfer among themselves. Since some users have limited mobile data plans and some don't, I would like to know if I could develop a switch to disable mobile data for my specific app. A bit like what Android's own Data usage -> mobile -> App ->"Restrict background data" does...

它说(并执行),它禁止移动数据网络上的后台数据仅Wi-Fi将(如果可用),我想这一点,但不只是在背景上。

it says (and does) that it "disables background data on mobile data network only. Wi-Fi will be used if available.", I want that but not just on background.

我知道我不能改变的限制后台数据选项,因为这将使它无用的,如果应用程序可以untoggle ...但有什么办法,我可以说编程现在我的应用程序被阻止访问移动数据,现在是不是?

I do know that I can't change the "Restrict background data" option, as it would make it useless if applications could untoggle it ... but is there a way i can programmatically say now my app is blocked access to mobile data, now it isn't?

作为洞察为什么我想这一点,我想,当用户选择一个给定的选项(我没有和工作),但也有一些数据泄露(每天一些KBS)不调用远程访问调用,我不能似乎阻止......无论是由于系统保持HTTP连接或其它一些模糊的原因...

as insight for why I want this, I am trying to not call remote access calls when the user selects a given option(which I did and works), but there are some data leakage (some kbs per day) that I cant seem to block ... either due to the system keeping http connections or some other obscure reason...

我看到的DDMS透视图的Eclipse在网络统计这些数据传输为我的应用程序。

I'm seeing these data transfers on DDMS perspective on eclipse on the network statistics for my app.

感谢您的帮助。

推荐答案

而不是禁用的,这将是很好的检查活动连接WiFi或没有,如果没有WIFI的话不要做任何服务器端通信。

Instead of disabling, it will be good to check if active connection is wifi or not, if not wifi then don't do any server side communication.

检查以下螺纹的例子。

怎么看的WiFi连接在机器人

ConnectivityManager connManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

if (mWifi.isConnected()) {
    // Do whatever
}

记得添加

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>

您AndroidManifest.manifest为此工作。

to your AndroidManifest.manifest for this to work.

这篇关于如何以编程方式禁用移动数据为我的应用程序只的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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