gpt4 book ai didi

android - 启用/禁用来自android代码的使用数据包

转载 作者:太空狗 更新时间:2023-10-29 14:27:06 29 4
gpt4 key购买 nike

我想在我的应用程序中禁用或启用在 android 设备中使用数据包,我在下面的代码中使用了该应用程序:

try {
Method dataConnSwitchmethod;
Class telephonyManagerClass;
Object ITelephonyStub;
Class ITelephonyClass;

TelephonyManager telephonyManager = (TelephonyManager) NetworkMonitorDemoAppActivity.this.getSystemService(Context.TELEPHONY_SERVICE);

if (telephonyManager.getDataState() == TelephonyManager.DATA_CONNECTED) {
isEnabled = true;
} else {
isEnabled = false;
}

telephonyManagerClass = Class.forName(telephonyManager.getClass().getName());
Method getITelephonyMethod = telephonyManagerClass.getDeclaredMethod("getITelephony");
getITelephonyMethod.setAccessible(true);
ITelephonyStub = getITelephonyMethod.invoke(telephonyManager);
ITelephonyClass = Class
.forName(ITelephonyStub.getClass().getName());

if (isEnabled) {
dataConnSwitchmethod = ITelephonyClass.getDeclaredMethod("disableDataConnectivity");
} else {
dataConnSwitchmethod = ITelephonyClass.getDeclaredMethod("enableDataConnectivity");
}
dataConnSwitchmethod.setAccessible(true);
dataConnSwitchmethod.invoke(ITelephonyStub);
} catch (Exception e) {
System.out.println("error is occured in uses data packet enable & disable :-"+e.getMessage());
}

但是这段代码不能正常工作。我的 friend 可以帮我解决这个问题吗?

最佳答案

我认为您在 SO answer https://stackoverflow.com/a/4304110/582571 中引用了代码

上面链接中的评论提到“这在 Gingerbread 2.3+ 上不起作用”请在此处查看另一个 SO 答案中的详细说明 https://stackoverflow.com/a/5095956/582571

所以最好不要制作任何带有隐藏 API 的应用

关于android - 启用/禁用来自android代码的使用数据包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11244998/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com