代码控制数据流量开关
2015-01-26 23:26
267 查看
/** * 操作数据流量 * GPRS网络开关 反射ConnectivityManager中hide的方法setMobileDataEnabled 可以开启和关闭GPRS网络 * @param isEnable * @throws Exception */ public static void setGprsStatus(Context context,boolean isEnable){ ConnectivityManager mConnectivityManager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); Class<?> cmClass = mConnectivityManager.getClass(); Class<?>[] argClasses = new Class[1]; argClasses[0] = boolean.class; // 反射ConnectivityManager中hide的方法setMobileDataEnabled,可以开启和关闭GPRS网络 Method method; try { method = cmClass.getMethod("setMobileDataEnabled", argClasses); method.invoke(mConnectivityManager, isEnable); } catch (NoSuchMethodException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } catch (IllegalAccessException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } catch (InvocationTargetException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } }
这段代码可以设置GPRS的状态,用到了反射。
相关文章推荐
- 代码控制数据流量开关
- Android中使用代码控制Wifi及数据连接网络开关
- Android中使用代码控制Wifi及数据连接网络开关
- 第二人生的源码分析(三十一)接收数据的流量控制
- 蔡军生先生第二人生的源码分析(二十七)发送数据的流量控制
- nginx的upstream模块数据转发过程及流量控制分析
- 编写高质量代码-OC 第2章 数据类型、集合和控制语句
- 不仅仅只控制代码,也要控制数据
- gnugk代码解读之三:媒体通道数据和媒体控制通道数据的路由
- java使用Scanner类循环从控制台中获取数据的方法代码。
- 代码控制android手机网络的开关
- 汇编语言控制屏幕信息提示,然后输入数据的代码
- 第二人生的源码分析(三十一)接收数据的流量控制
- android 2.3 数据流量开关 移动网络的数据访问功能,非APN开关
- 数据写入流量控制
- 修改设置中数据流量小部件开关跟设置中流量开关同步
- 第二人生的源码分析(二十七)发送数据的流量控制
- curl数据采集系列之代码分离及并行逻辑控制函数web_spider
- 代码中添加事务控制 VS(数据库存储过程+事务) 保证数据的完整性与一致性
- PB 数据窗口打印详细控制代码