TrafficStats向我们提供有关哪个应用程序消耗带宽的信息。Android - 如何防止应用程序通过其他应用程序访问互联网
我想编写一个应用程序,在需要时禁用/启用一些其他应用程序的互联网使用。
我看到有一些谷歌播放应用程序这样做,但如何?
TrafficStats向我们提供有关哪个应用程序消耗带宽的信息。Android - 如何防止应用程序通过其他应用程序访问互联网
我想编写一个应用程序,在需要时禁用/启用一些其他应用程序的互联网使用。
我看到有一些谷歌播放应用程序这样做,但如何?
private void setMobileDataEnabled(Context context, boolean enabled) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
final ConnectivityManager conman = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
final Class conmanClass = Class.forName(conman.getClass().getName());
final Field connectivityManagerField = conmanClass.getDeclaredField("mService");
connectivityManagerField.setAccessible(true);
final Object connectivityManager = connectivityManagerField.get(conman);
final Class connectivityManagerClass = Class.forName(connectivityManager.getClass().getName());
final Method setMobileDataEnabledMethod = connectivityManagerClass.getDeclaredMethod("setMobileDataEnabled", Boolean.TYPE);
setMobileDataEnabledMethod.setAccessible(true);
setMobileDataEnabledMethod.invoke(connectivityManager, enabled);
}
不要忘了此行添加到您的清单文件
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
为使用iptables
很好的例子(展示如何编写防火墙程序)的考虑是orWall
将您的应用放在Orbot后面,并阻止所有不需要的流量 走。
Orwall page also pointing to GitHub source Codes
“这不是一个解决方案。这只是另一个程序在做这件事情。我问如何编写这样一个程序..这可以启用或禁用对互联网接入所以-1“
你知道如何阅读吗?
iptables是一个用户空间应用程序,它允许系统管理员配置Linux内核防火墙提供的表(实现为不同的Netfilter模块)以及它存储的链和规则。不同的内核模块和程序目前用于不同的协议; iptables适用于IPv4,ip6tables适用于IPv6,arptables适用于ARP,以及ebtables适用于以太网帧。
iptables需要提升权限才能运行,必须由root用户执行,否则无法运行。在大多数Linux系统中,iptables安装为/ usr/sbin/iptables并记录在其手册页中,可以在安装时使用man iptables打开。它也可以在/ sbin/iptables中找到,但由于iptables更像是一种服务而不是“基本二进制”,所以首选位置仍然是/ usr/sbin。
术语iptables通常也用于包含性地引用内核级组件。 x_tables是内核模块的名称,它携带所有四个模块使用的共享代码部分,这些模块还提供用于扩展的API;随后,Xtables或多或少地用于指代整个防火墙(v4,v6,arp和eb)体系结构。
的iptables的继任者是nftables,这是合并到Linux内核主线内核版本3.13,它发布于2014年1月19日
这不是一个解决方案。这只是另一个做这件事的程序。我正在问如何编写这样的程序。这可以启用或禁用其他应用程序的Internet访问。所以-1 –
我如何设置防止该应用程序的网络使用情况? –
使用Connectivity Manager类,我们可以访问Internet网络: ConnectivityManager connec =(ConnectivityManager)getSystemService(Context。CONNECTIVITY_SERVICE); – Rahul
@Rahul - 人们为什么喜欢玩火? – ceph3us