如何在 Android 上以编程方式在 3G 和 4G 之间切换?

发布于 2024-12-23 18:18:18 字数 143 浏览 2 评论 0原文

我对此进行了一些研究,我认为这是不可能的,但认为某些事情在 Android 平台上不可能是亵渎的。我们的想法是创建一个可以在 3G 和 4G 之间切换的小部件,以节省电池,而无需输入设置。从本质上讲,设置菜单不只是另一个应用程序,所以它应该可以在其他应用程序中正确使用吗?

I've looked into it some and I'm thinking it's not possible, but to think that something isn't possible on the Android platform is blasphemous. The idea is to create a widget that toggles between 3G and 4G to save battery without having to enter the settings. In essence isn't the settings menu just another application so it should be possible in other applications correct?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

‖放下 2024-12-30 18:18:18

作为标准的第三方应用程序,这是不可能的。

但是,如果您的应用程序是平台签名的(或预安装的特权应用程序)并且可以访问隐藏的框架 API,则可以通过 TelephonyManager 类实现这一点。

例如:

import android.telephony.TelephonyManager;

...

TelephonyManager telephonyManager = new TelephonyManager(context, 1); // 1 = SIM slot
telephonyManager.setPreferredNetworkType(1, newNetworkMode); // 1 = SIM slot, newNetworkMode = the desired network mode defined in RILConstants.java

我的 RILConstants 中的网络模式如下:

/* NETWORK_MODE_* See ril.h RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE */
int NETWORK_MODE_WCDMA_PREF     = 0; /* GSM/WCDMA (WCDMA preferred) */
int NETWORK_MODE_GSM_ONLY       = 1; /* GSM only */
int NETWORK_MODE_WCDMA_ONLY     = 2; /* WCDMA only */
int NETWORK_MODE_GSM_UMTS       = 3; /* GSM/WCDMA (auto mode, according to PRL)
                                        AVAILABLE Application Settings menu*/
int NETWORK_MODE_CDMA           = 4; /* CDMA and EvDo (auto mode, according to PRL)
                                        AVAILABLE Application Settings menu*/
int NETWORK_MODE_CDMA_NO_EVDO   = 5; /* CDMA only */
int NETWORK_MODE_EVDO_NO_CDMA   = 6; /* EvDo only */
int NETWORK_MODE_GLOBAL         = 7; /* GSM/WCDMA, CDMA, and EvDo (auto mode, according to PRL)
                                        AVAILABLE Application Settings menu*/
int NETWORK_MODE_LTE_CDMA_EVDO  = 8; /* LTE, CDMA and EvDo */
int NETWORK_MODE_LTE_GSM_WCDMA  = 9; /* LTE, GSM/WCDMA */
int NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA = 10; /* LTE, CDMA, EvDo, GSM/WCDMA */
int NETWORK_MODE_LTE_ONLY       = 11; /* LTE Only mode. */
int NETWORK_MODE_LTE_WCDMA      = 12; /* LTE/WCDMA */
int NETWORK_MODE_TDSCDMA_ONLY            = 13; /* TD-SCDMA only */
int NETWORK_MODE_TDSCDMA_WCDMA           = 14; /* TD-SCDMA and WCDMA */
int NETWORK_MODE_LTE_TDSCDMA             = 15; /* TD-SCDMA and LTE */
int NETWORK_MODE_TDSCDMA_GSM             = 16; /* TD-SCDMA and GSM */
int NETWORK_MODE_LTE_TDSCDMA_GSM         = 17; /* TD-SCDMA,GSM and LTE */
int NETWORK_MODE_TDSCDMA_GSM_WCDMA       = 18; /* TD-SCDMA, GSM/WCDMA */
int NETWORK_MODE_LTE_TDSCDMA_WCDMA       = 19; /* TD-SCDMA, WCDMA and LTE */
int NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA   = 20; /* TD-SCDMA, GSM/WCDMA and LTE */
int NETWORK_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA  = 21; /*TD-SCDMA,EvDo,CDMA,GSM/WCDMA*/
int NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA = 22; /* TD-SCDMA/LTE/GSM/WCDMA, CDMA, and EvDo */

As a standard 3rd party app this is not possible.

But if your app is platform signed (or a pre-installed privileged app) and have access to the hidden framework APIs then this is possible via the TelephonyManager class.

E.g:

import android.telephony.TelephonyManager;

...

TelephonyManager telephonyManager = new TelephonyManager(context, 1); // 1 = SIM slot
telephonyManager.setPreferredNetworkType(1, newNetworkMode); // 1 = SIM slot, newNetworkMode = the desired network mode defined in RILConstants.java

The network modes in my RILConstants were as follows:

/* NETWORK_MODE_* See ril.h RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE */
int NETWORK_MODE_WCDMA_PREF     = 0; /* GSM/WCDMA (WCDMA preferred) */
int NETWORK_MODE_GSM_ONLY       = 1; /* GSM only */
int NETWORK_MODE_WCDMA_ONLY     = 2; /* WCDMA only */
int NETWORK_MODE_GSM_UMTS       = 3; /* GSM/WCDMA (auto mode, according to PRL)
                                        AVAILABLE Application Settings menu*/
int NETWORK_MODE_CDMA           = 4; /* CDMA and EvDo (auto mode, according to PRL)
                                        AVAILABLE Application Settings menu*/
int NETWORK_MODE_CDMA_NO_EVDO   = 5; /* CDMA only */
int NETWORK_MODE_EVDO_NO_CDMA   = 6; /* EvDo only */
int NETWORK_MODE_GLOBAL         = 7; /* GSM/WCDMA, CDMA, and EvDo (auto mode, according to PRL)
                                        AVAILABLE Application Settings menu*/
int NETWORK_MODE_LTE_CDMA_EVDO  = 8; /* LTE, CDMA and EvDo */
int NETWORK_MODE_LTE_GSM_WCDMA  = 9; /* LTE, GSM/WCDMA */
int NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA = 10; /* LTE, CDMA, EvDo, GSM/WCDMA */
int NETWORK_MODE_LTE_ONLY       = 11; /* LTE Only mode. */
int NETWORK_MODE_LTE_WCDMA      = 12; /* LTE/WCDMA */
int NETWORK_MODE_TDSCDMA_ONLY            = 13; /* TD-SCDMA only */
int NETWORK_MODE_TDSCDMA_WCDMA           = 14; /* TD-SCDMA and WCDMA */
int NETWORK_MODE_LTE_TDSCDMA             = 15; /* TD-SCDMA and LTE */
int NETWORK_MODE_TDSCDMA_GSM             = 16; /* TD-SCDMA and GSM */
int NETWORK_MODE_LTE_TDSCDMA_GSM         = 17; /* TD-SCDMA,GSM and LTE */
int NETWORK_MODE_TDSCDMA_GSM_WCDMA       = 18; /* TD-SCDMA, GSM/WCDMA */
int NETWORK_MODE_LTE_TDSCDMA_WCDMA       = 19; /* TD-SCDMA, WCDMA and LTE */
int NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA   = 20; /* TD-SCDMA, GSM/WCDMA and LTE */
int NETWORK_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA  = 21; /*TD-SCDMA,EvDo,CDMA,GSM/WCDMA*/
int NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA = 22; /* TD-SCDMA/LTE/GSM/WCDMA, CDMA, and EvDo */
眼角的笑意。 2024-12-30 18:18:18

SDK 中没有提供允许您执行此操作的 API。这并不是说 Android 不支持网络选择首选项;而是说 Android 不支持网络选择首选项。这只是意味着 Google 认为不适合授予普通人(应用程序开发人员)访问必要 API 的权限,正如 alextsc_off 所暗示的那样。

There are no APIs surfaced in the SDK that permit you to do this. That's not to say that Android doesn't support network selection preferences; it just means that Google hasn't seen fit to grant mere mortals (app developers) access to the requisite APIs, as alextsc_off alludes to.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文