本文介绍了Android 4.0的4G切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是Verizon的LTE版本三星GALAXY Nexus的。

This is for the Verizon LTE version of the Samsung Galaxy Nexus.

我负责写一个小的应用程序,这将有效地禁用/启用4G功能。这可以通过手动设置&gt完成;移动网络>网络模式并选择每个 LTE / CDMA (4G启用)或 CDMA (3G只)。

I am tasked with writing a tiny app that will effectively disable/enable 4G capability. This can be done manually via settings > mobile network > network mode and choosing either LTE/CDMA (4g enabled) or CDMA (3g only).

我还没有尝试任何事情,因为Android的发展是不是我的强项。我要找的指导......例子,code样品等我假定这的的几乎是一个一行,但它一直是我的经验,随着Android的发展没有什么是简单因为它出现。

I have not tried anything yet because Android development isn't my strong suit. I am looking for guidance... examples, code samples etc. I am assuming this should almost be a one-liner, but it has been my experience that with Android development nothing is as simple as it appears.

任何帮助将大大AP preciated。

Any help will be greatly appreciated.

推荐答案

有一个preference中的类:

There is a preference in the Settings.Secure class that is hidden from the SDK:

    /**
     * The preferred network mode   7 = Global
     *                              6 = EvDo only
     *                              5 = CDMA w/o EvDo
     *                              4 = CDMA / EvDo auto
     *                              3 = GSM / WCDMA auto
     *                              2 = WCDMA only
     *                              1 = GSM only
     *                              0 = GSM / WCDMA preferred
     * @hide
     */
    public static final String PREFERRED_NETWORK_MODE =
            "preferred_network_mode";

您可以使用反射在这个或只是本地化不断到您的项目。这里的问题是,你不能改变这个设置的值(与所有安全设置),则只能读取它。上述的值是不是唯一可能的,实际上有几个位于com.android.internal.telephony.RILConstants,这是再一次从SDK隐藏,将需要思考访问

You could use Reflection on this or just localize the constant to your project. The problem with this is that you cannot change the value of this setting (as with all secure settings), you can only read it. The aforementioned values are not the only possible ones, there are actually a few more located in com.android.internal.telephony.RILConstants, which is again hidden from the SDK and would require Reflection to access.

有一个在 TelephonyManager 另一个隐藏的方法,但是这又是只读没有其他方法设置该常数。这会告诉你你想知道,是否该设备被设置为LTE / CDMA(LTE_ON_CDMA_TRUE)或CDMA只有到底是什么(LTE_ON_CDMA_FALSE):

There is another hidden method in TelephonyManager, but again it is read only there is no other method for setting this constant. This would tell you exactly what you want to know, whether the device is set to "LTE/ CDMA" (LTE_ON_CDMA_TRUE) or "CDMA only" (LTE_ON_CDMA_FALSE):

/**
 * Return if the current radio is LTE on CDMA. This
 * is a tri-state return value as for a period of time
 * the mode may be unknown.
 *
 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
 * or {@link Phone#LTE_ON_CDMA_TRUE}
 *
 * @hide
 */
public int getLteOnCdmaMode() {
    try {
        return getITelephony().getLteOnCdmaMode();
    } catch (RemoteException ex) {
        // Assume no ICC card if remote exception which shouldn't happen
        return Phone.LTE_ON_CDMA_UNKNOWN;
    } catch (NullPointerException ex) {
        // This could happen before phone restarts due to crashing
        return Phone.LTE_ON_CDMA_UNKNOWN;
    }
}

从我的研究,你不能让没有root访问权限,例如应用程序和使用像 setprop 命令行,但即使如此,你可能需要重新启动整个电话过程中,为了使此设置生效。

From my research you could not make such an application without root access and using something like setprop from the command line, but even then you may need to restart the entire Telephony process in order for this setting to take effect.

最后,如果你仍然有兴趣看到com.android.phone.Settings看系统如何处理这种切换。这是相当复杂的,正如我提到的,需要的权限,一个正常的Andr​​oid应用程序将不会被批准。

Finally, if you are still interested see com.android.phone.Settings to see how the system handles this toggle. It is rather elaborate, and as I mentioned would require permissions that a normal Android application would not be granted.

这篇关于Android 4.0的4G切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-03 14:38