Android的信号强度

Android的信号强度

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

问题描述

有没有什么方法来获得两个SIM卡的信号强度。我搜索了很多,但我找不到任何解决方案。也许是没有任何登记在第二个SIM卡接收器的方法?我工作的是Android 5.0,我知道,在这个版本的Andr​​oid官方不支持双卡的解决方案。我只找到这里面几乎适合对我说:
Check手机是双卡

Is there any method to get signal strength on both sim cards. I search a lot but I couldn't find any solution. Maybe is there any method to register receiver on second sim card ? I'm working on Android 5.0 and I know that on this version Android officially does not support dual sim solutions. I found only this which nearly fits to me:Check whether the phone is dual SIMAndroid dual SIM signal strength

第二个链接presents某种程度上但由于方法的 TelephonyManager.listenGemini 的不适,我不能用它

Second link presents some way but I cannot use it because method TelephonyManager.listenGemini is not available

任何帮助吗?

推荐答案

请注意:以下是具体一些的Andr​​oid 5.0设备。它采用隐藏式接口的是Android 5.0,并不会在早期以后版本。尤其是,订阅ID更改从 INT 当API中API 22(暴露,而您应该用官方的API反正)。

Please note: the following is specific to some Android 5.0 devices. It uses hidden interface in Android 5.0, and will not work in earlier AND later versions. In particular, the subscription id changed from long to int when the API is exposed in API 22 (for which you should use the official API anyway).

有关的Andr​​oid 5.0在HTC M8,您可以尝试下面让两个SIM卡的信号强度:

For Android 5.0 on HTC M8, you may try the following to get the signal strength of both sim cards:

重写 PhoneStateListener 及其保护的内部变量长mSubId 。由于受保护的变量是隐藏的,你需要使用反射。

Overriding PhoneStateListener and its protected internal variable long mSubId. Since the protected variable is hidden you will need to use reflection.

public class MultiSimListener extends PhoneStateListener {

    private Field subIdField;
    private long subId = -1;

    public MultiSimListener (long subId) {
        super();
        try {
            // Get the protected field mSubId of PhoneStateListener and set it
            subIdField = this.getClass().getSuperclass().getDeclaredField("mSubId");
            subscriptionField.setAccessible(true);
            subscriptionField.set(this, subId);
            this.subId = subId;
        } catch (NoSuchFieldException e) {

        } catch (IllegalAccessException e) {

        } catch (IllegalArgumentException e) {

        }
    }

    @Override
    public void onSignalStrengthsChanged(SignalStrength signalStrength) {
        // Handle the event here, subId indicates the subscription id if > 0
    }

}

您还需要获得积极认购的ID从 SubscriptionManager 的列表中实例化类。再次 SubscriptionManager 隐藏在5.0。

You also need to get the list of active subscription IDs from the SubscriptionManager for instantiating the class. Again SubscriptionManager is hidden in 5.0.

final Class<?> tmClassSM = Class.forName("android.telephony.SubscriptionManager");
// Static method to return list of active subids
Method methodGetSubIdList = tmClassSM.getDeclaredMethod("getActiveSubIdList");
long[] subIdList = (long[])methodGetSubIdList.invoke(null);

然后就可以通过 subIdList 迭代创建 MultiSimListener 的实例。例如。

Then you can iterate through the subIdList to create instances of MultiSimListener. e.g.

MultiSimListener listener[subIdList[i]] = new MultiSimListener(subIdList[i]);

您可以调用 TelephonyManager.listen 像往常一样,为每一个听众。

You can then call TelephonyManager.listen as usual, for each of the listeners.

您需要将错误和Android版本/设备检查添加到code,因为它仅适用于特定设备/版本。

You will need to add error and Android version / device check to the code, as it works only on specific devices / version.

这篇关于Android的信号强度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 06:35