gpt4 book ai didi

android - 如何在 Android 5.0 上以编程方式关闭/打开 3G/4G/数据?

转载 作者:行者123 更新时间:2023-11-29 01:30:38 24 4
gpt4 key购买 nike

为什么这段代码不能在 android 5.0 上运行?

我在 android 4.3 上测试,工作但在 android 5.0 上不工作。

请帮助我。

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 java.lang.reflect.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);
}

最佳答案

Google 已实用化地取消了他们的数据开/关 API。您可以查看在 link 上提交的问题.

如果您想了解更多详细信息,请在 link 上找到详细答案哪里有详细的讨论

如果你觉得这有帮助,请采纳它作为答案

关于android - 如何在 Android 5.0 上以编程方式关闭/打开 3G/4G/数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31387789/

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