Android dual SIM signal strength
Asked Answered
C

4

7

I have been trying to get access to some features on my android dual sim phone (the brand is LKD). I have managed to get the functions for TelephonyManager and ITelephony through java reflection, and got them to run. However i want to get the signal strength for both of the sim cards and i cannot see a way to do this through the reflection. I can get the first sim card in slot 1 through having a PhoneStateListener with the function onSignalStrengthsChanged().

Does anyone have some tips for this? Functions i got from reflection:

###stanard methods:###
adjustModemRadioPower - boolean: int, int
adjustModemRadioPowerByBand - boolean: int, int
btSimapApduRequest - int: int, java.lang.String, android.telephony.BtSimapOperResponse
btSimapConnectSIM - int: int, android.telephony.BtSimapOperResponse
btSimapDisconnectSIM - int: 
btSimapPowerOffSIM - int: 
btSimapPowerOnSIM - int: int, android.telephony.BtSimapOperResponse
btSimapResetSIM - int: int, android.telephony.BtSimapOperResponse
disableLocationUpdates - void: 
disableLocationUpdatesGemini - void: int
enableLocationUpdates - void: 
enableLocationUpdatesGemini - void: int
equals - boolean: java.lang.Object
from - class android.telephony.TelephonyManager: android.content.Context
getAllCellInfo - interface java.util.List: 
getCallState - int: 
getCallStateGemini - int: int
getCdmaEriIconIndex - int: 
getCdmaEriIconMode - int: 
getCdmaEriText - class java.lang.String: 
getCellLocation - class android.telephony.CellLocation: 
getCellLocationGemini - class android.telephony.CellLocation: int
getClass - class java.lang.Class: 
getCompleteVoiceMailNumber - class java.lang.String: 
getCurrentPhoneType - int: 
getDataActivity - int: 
getDataState - int: 
getDataStateGemini - int: int
getDefault - class android.telephony.TelephonyManager: 
getDeviceId - class java.lang.String: 
getDeviceIdGemini - class java.lang.String: int
getDeviceSoftwareVersion - class java.lang.String: 
getIccCardType - class java.lang.String: 
getIccCardTypeGemini - class java.lang.String: int
getIsimDomain - class java.lang.String: 
getIsimImpi - class java.lang.String: 
getIsimImpu - class [Ljava.lang.String;: 
getLine1AlphaTag - class java.lang.String: 
getLine1AlphaTagGemini - class java.lang.String: int
getLine1Number - class java.lang.String: 
getLine1NumberGemini - class java.lang.String: int
getLteOnCdmaMode - int: 
getLteOnCdmaModeStatic - int: 
getMaxPdpNum - int: int
getMissedCallCount - int: 
getMobileRevisionAndIMEI - void: int, android.os.Message
getMsisdn - class java.lang.String: 
getNeighboringCellInfo - interface java.util.List: 
getNeighboringCellInfoGemini - interface java.util.List: int
getNetworkClass - int: int
getNetworkCountryIso - class java.lang.String: 
getNetworkCountryIsoGemini - class java.lang.String: int
getNetworkOperator - class java.lang.String: 
getNetworkOperatorGemini - class java.lang.String: int
getNetworkOperatorName - class java.lang.String: 
getNetworkOperatorNameGemini - class java.lang.String: int
getNetworkType - int: 
getNetworkTypeGemini - int: int
getNetworkTypeName - class java.lang.String: 
getNetworkTypeName - class java.lang.String: int
getNetworkTypeNameGemini - class java.lang.String: int
getPhoneType - int: 
getPhoneType - int: int
getPhoneTypeGemini - int: int
getRadioType - int: int
getSN - class java.lang.String: 
getSimCountryIso - class java.lang.String: 
getSimCountryIsoGemini - class java.lang.String: int
getSimOperator - class java.lang.String: 
getSimOperatorGemini - class java.lang.String: int
getSimOperatorName - class java.lang.String: 
getSimOperatorNameGemini - class java.lang.String: int
getSimSerialNumber - class java.lang.String: 
getSimSerialNumberGemini - class java.lang.String: int
getSimState - int: 
getSimStateGemini - int: int
getSmsDefaultSim - int: 
getSpNameInEfSpn - class java.lang.String: 
getSpNameInEfSpnGemini - class java.lang.String: int
getSubscriberId - class java.lang.String: 
getSubscriberIdGemini - class java.lang.String: int
getVoiceMailAlphaTag - class java.lang.String: 
getVoiceMailAlphaTagGemini - class java.lang.String: int
getVoiceMailNumber - class java.lang.String: 
getVoiceMailNumberGemini - class java.lang.String: int
getVoiceMessageCount - int: 
getVoiceMessageCountGemini - int: int
hasIccCard - boolean: 
hasIccCardGemini - boolean: int
hashCode - int: 
isIccCardProviderAsMvno - boolean: 
isIccCardProviderAsMvnoGemini - boolean: int
isNetworkRoaming - boolean: 
isNetworkRoamingGemini - boolean: int
isOperatorMvnoForEfPnn - class java.lang.String: 
isOperatorMvnoForEfPnnGemini - class java.lang.String: int
isOperatorMvnoForImsi - class java.lang.String: 
isOperatorMvnoForImsiGemini - class java.lang.String: int
isSmsCapable - boolean: 
isVoiceCapable - boolean: 
listen - void: android.telephony.PhoneStateListener, int
listenGemini - void: android.telephony.PhoneStateListener, int, int
notify - void: 
notifyAll - void: 
simAuth - class java.lang.String: java.lang.String
simAuthGemini - class java.lang.String: java.lang.String, int
toString - class java.lang.String: 
uSimAuth - class java.lang.String: java.lang.String, java.lang.String
uSimAuthGemini - class java.lang.String: java.lang.String, java.lang.String, int
wait - void: 
wait - void: long
wait - void: long, int

###declared methods###
adjustModemRadioPower - boolean: int, int
adjustModemRadioPowerByBand - boolean: int, int
btSimapApduRequest - int: int, java.lang.String, android.telephony.BtSimapOperResponse
btSimapConnectSIM - int: int, android.telephony.BtSimapOperResponse
btSimapDisconnectSIM - int: 
btSimapPowerOffSIM - int: 
btSimapPowerOnSIM - int: int, android.telephony.BtSimapOperResponse
btSimapResetSIM - int: int, android.telephony.BtSimapOperResponse
disableLocationUpdates - void: 
disableLocationUpdatesGemini - void: int
enableLocationUpdates - void: 
enableLocationUpdatesGemini - void: int
getAllCellInfo - interface java.util.List: 
getCallState - int: 
getCallStateGemini - int: int
getCdmaEriIconIndex - int: 
getCdmaEriIconMode - int: 
getCdmaEriText - class java.lang.String: 
getCellLocation - class android.telephony.CellLocation: 
getCellLocationGemini - class android.telephony.CellLocation: int
getCompleteVoiceMailNumber - class java.lang.String: 
getCurrentPhoneType - int: 
getDataActivity - int: 
getDataState - int: 
getDataStateGemini - int: int
getDeviceId - class java.lang.String: 
getDeviceIdGemini - class java.lang.String: int
getDeviceSoftwareVersion - class java.lang.String: 
getIccCardType - class java.lang.String: 
getIccCardTypeGemini - class java.lang.String: int
getIsimDomain - class java.lang.String: 
getIsimImpi - class java.lang.String: 
getIsimImpu - class [Ljava.lang.String;: 
getLine1AlphaTag - class java.lang.String: 
getLine1AlphaTagGemini - class java.lang.String: int
getLine1Number - class java.lang.String: 
getLine1NumberGemini - class java.lang.String: int
getLteOnCdmaMode - int: 
getMissedCallCount - int: 
getMobileRevisionAndIMEI - void: int, android.os.Message
getMsisdn - class java.lang.String: 
getNeighboringCellInfo - interface java.util.List: 
getNeighboringCellInfoGemini - interface java.util.List: int
getNetworkCountryIso - class java.lang.String: 
getNetworkCountryIsoGemini - class java.lang.String: int
getNetworkOperator - class java.lang.String: 
getNetworkOperatorGemini - class java.lang.String: int
getNetworkOperatorName - class java.lang.String: 
getNetworkOperatorNameGemini - class java.lang.String: int
getNetworkType - int: 
getNetworkTypeGemini - int: int
getNetworkTypeName - class java.lang.String: 
getNetworkTypeNameGemini - class java.lang.String: int
getPhoneType - int: 
getPhoneTypeGemini - int: int
getSN - class java.lang.String: 
getSimCountryIso - class java.lang.String: 
getSimCountryIsoGemini - class java.lang.String: int
getSimOperator - class java.lang.String: 
getSimOperatorGemini - class java.lang.String: int
getSimOperatorName - class java.lang.String: 
getSimOperatorNameGemini - class java.lang.String: int
getSimSerialNumber - class java.lang.String: 
getSimSerialNumberGemini - class java.lang.String: int
getSimState - int: 
getSimStateGemini - int: int
getSmsDefaultSim - int: 
getSpNameInEfSpn - class java.lang.String: 
getSpNameInEfSpnGemini - class java.lang.String: int
getSubscriberId - class java.lang.String: 
getSubscriberIdGemini - class java.lang.String: int
getVoiceMailAlphaTag - class java.lang.String: 
getVoiceMailAlphaTagGemini - class java.lang.String: int
getVoiceMailNumber - class java.lang.String: 
getVoiceMailNumberGemini - class java.lang.String: int
getVoiceMessageCount - int: 
getVoiceMessageCountGemini - int: int
hasIccCard - boolean: 
hasIccCardGemini - boolean: int
isIccCardProviderAsMvno - boolean: 
isIccCardProviderAsMvnoGemini - boolean: int
isNetworkRoaming - boolean: 
isNetworkRoamingGemini - boolean: int
isOperatorMvnoForEfPnn - class java.lang.String: 
isOperatorMvnoForEfPnnGemini - class java.lang.String: int
isOperatorMvnoForImsi - class java.lang.String: 
isOperatorMvnoForImsiGemini - class java.lang.String: int
isSmsCapable - boolean: 
isVoiceCapable - boolean: 
listen - void: android.telephony.PhoneStateListener, int
listenGemini - void: android.telephony.PhoneStateListener, int, int
simAuth - class java.lang.String: java.lang.String
simAuthGemini - class java.lang.String: java.lang.String, int
uSimAuth - class java.lang.String: java.lang.String, java.lang.String
uSimAuthGemini - class java.lang.String: java.lang.String, java.lang.String, int
from - class android.telephony.TelephonyManager: android.content.Context
getDefault - class android.telephony.TelephonyManager: 
getDefaultSim - int: 
getITelephony - interface com.android.internal.telephony.ITelephony: 
getLteOnCdmaModeStatic - int: 
getMaxPdpNum - int: int
getNetworkClass - int: int
getNetworkTypeName - class java.lang.String: int
getPhoneType - int: int
getPhoneTypeFromNetworkType - int: 
getPhoneTypeFromProperty - int: 
getProcCmdLine - class java.lang.String: 
getRadioType - int: int
getSubscriberInfo - interface com.android.internal.telephony.IPhoneSubInfo: 
getSubscriberInfo - interface com.android.internal.telephony.IPhoneSubInfo: int

###ITelephony methods###
adjustModemRadioPower - boolean: int, int
adjustModemRadioPowerByBand - boolean: int, int, int
answerRingingCall - void: 
answerRingingCallGemini - void: int
aquire3GSwitchLock - int: 
asBinder - interface android.os.IBinder: 
btSimapApduRequest - int: int, java.lang.String, android.telephony.BtSimapOperResponse
btSimapConnectSIM - int: int, android.telephony.BtSimapOperResponse
btSimapDisconnectSIM - int: 
btSimapPowerOffSIM - int: 
btSimapPowerOnSIM - int: int, android.telephony.BtSimapOperResponse
btSimapResetSIM - int: int, android.telephony.BtSimapOperResponse
call - void: java.lang.String
callGemini - void: java.lang.String, int
cancelMissedCallsNotification - void: 
cancelMissedCallsNotificationGemini - void: int
cleanupApnTypeGemini - int: java.lang.String, int
closeIccLogicalChannel - boolean: int
closeIccLogicalChannelGemini - boolean: int, int
dial - void: java.lang.String
dialGemini - void: java.lang.String, int
disableApnType - int: java.lang.String
disableApnTypeGemini - int: java.lang.String, int
disableDataConnectivity - boolean: 
disableDataConnectivityGemini - int: int
disableLocationUpdates - void: 
disableLocationUpdatesGemini - void: int
enableApnType - int: java.lang.String
enableApnTypeGemini - int: java.lang.String, int
enableDataConnectivity - boolean: 
enableDataConnectivityGemini - int: int
enableLocationUpdates - void: 
enableLocationUpdatesGemini - void: int
endCall - boolean: 
endCallGemini - boolean: int
equals - boolean: java.lang.Object
get3GCapabilitySIM - int: 
get3GSwitchAllowed3GSlots - int: 
getActivePhoneType - int: 
getActivePhoneTypeGemini - int: int
getAdnStorageInfo - class [I: int
getAllCellInfo - interface java.util.List: 
getCallState - int: 
getCallStateGemini - int: int
getCdmaEriIconIndex - int: 
getCdmaEriIconMode - int: 
getCdmaEriText - class java.lang.String: 
getCellLocation - class android.os.Bundle: 
getCellLocationGemini - class android.os.Bundle: int
getClass - class java.lang.Class: 
getDataActivity - int: 
getDataActivityGemini - int: int
getDataState - int: 
getDataStateGemini - int: int
getGateway - class java.lang.String: java.lang.String
getGatewayGemini - class java.lang.String: java.lang.String, int
getIccATR - class java.lang.String: 
getIccATRGemini - class java.lang.String: int
getIccCardType - class java.lang.String: 
getIccCardTypeGemini - class java.lang.String: int
getInterfaceDescriptor - class java.lang.String: 
getInterfaceName - class java.lang.String: java.lang.String
getInterfaceNameGemini - class java.lang.String: java.lang.String, int
getIpAddress - class java.lang.String: java.lang.String
getIpAddressGemini - class java.lang.String: java.lang.String, int
getLastError - int: 
getLastErrorGemini - int: int
getLine1AlphaTag - class java.lang.String: int
getLine1Number - class java.lang.String: int
getLteOnCdmaMode - int: 
getMissedCallCount - int: 
getMobileRevisionAndIMEI - void: int, android.os.Message
getNeighboringCellInfo - interface java.util.List: 
getNeighboringCellInfoGemini - interface java.util.List: int
getNetworkCountryIsoGemini - class java.lang.String: int
getNetworkOperatorGemini - class java.lang.String: int
getNetworkOperatorNameGemini - class java.lang.String: int
getNetworkType - int: 
getNetworkTypeGemini - int: int
getPendingMmiCodesGemini - int: int
getPreciseCallState - int: 
getSN - class java.lang.String: 
getScAddressGemini - class java.lang.String: int
getServiceState - class android.os.Bundle: 
getServiceStateGemini - class android.os.Bundle: int
getSimCountryIso - class java.lang.String: int
getSimIndicatorState - int: 
getSimIndicatorStateGemini - int: int
getSimOperator - class java.lang.String: int
getSimOperatorName - class java.lang.String: int
getSimSerialNumber - class java.lang.String: int
getSimState - int: int
getSmsDefaultSim - int: 
getSpNameInEfSpn - class java.lang.String: 
getSpNameInEfSpnGemini - class java.lang.String: int
getSubscriberId - class java.lang.String: int
getSubscriberInfo - interface com.android.internal.telephony.IPhoneSubInfo: int
getVoiceMailAlphaTag - class java.lang.String: int
getVoiceMailNumber - class java.lang.String: int
getVoiceMessageCount - int: 
getVoiceMessageCountGemini - int: int
handlePinMmi - boolean: java.lang.String
handlePinMmiGemini - boolean: java.lang.String, int
hasIccCard - boolean: 
hasIccCardGemini - boolean: int
hashCode - int: 
is3GSwitchLocked - boolean: 
is3GSwitchManualChange3GAllowed - boolean: 
is3GSwitchManualEnabled - boolean: 
isDataConnectivityPossible - boolean: 
isDataConnectivityPossibleGemini - boolean: int
isFDNEnabled - boolean: 
isFDNEnabledGemini - boolean: int
isIccCardProviderAsMvno - boolean: 
isIccCardProviderAsMvnoGemini - boolean: int
isIdle - boolean: 
isIdleGemini - boolean: int
isNetworkRoamingGemini - boolean: int
isOffhook - boolean: 
isOffhookGemini - boolean: int
isOperatorMvnoForEfPnn - class java.lang.String: 
isOperatorMvnoForEfPnnGemini - class java.lang.String: int
isOperatorMvnoForImsi - class java.lang.String: 
isOperatorMvnoForImsiGemini - class java.lang.String: int
isPhbReady - boolean: 
isPhbReadyGemini - boolean: int
isRadioOn - boolean: 
isRadioOnGemini - boolean: int
isRinging - boolean: 
isRingingGemini - boolean: int
isSimInsert - boolean: int
isSimPinEnabled - boolean: 
isTestIccCard - boolean: 
isTestIccCardGemini - boolean: int
isVTIdle - boolean: 
isVoiceIdle - boolean: 
needsOtaServiceProvisioning - boolean: 
notify - void: 
notifyAll - void: 
openIccLogicalChannel - int: java.lang.String
openIccLogicalChannelGemini - int: java.lang.String, int
openIccLogicalChannelWithSw - class [B: java.lang.String
openIccLogicalChannelWithSwGemini - class [B: java.lang.String, int
registerForSimModeChange - void: android.os.IBinder, int
release3GSwitchLock - boolean: int
set3GCapabilitySIM - boolean: int
setDataRoamingEnabledGemini - void: boolean, int
setDefaultPhone - void: int
setGprsConnType - void: int, int
setGprsTransferType - void: int
setGprsTransferTypeGemini - void: int, int
setRadio - boolean: boolean
setRadioOff - boolean: 
setRoamingIndicatorNeddedProperty - void: boolean, boolean
setScAddressGemini - void: java.lang.String, int
showCallScreen - boolean: 
showCallScreenGemini - boolean: int
showCallScreenWithDialpad - boolean: boolean
showCallScreenWithDialpadGemini - boolean: boolean, int
silenceRinger - void: 
silenceRingerGemini - void: int
simAuth - class java.lang.String: java.lang.String
simAuthGemini - class java.lang.String: java.lang.String, int
supplyPin - boolean: java.lang.String
supplyPinGemini - boolean: java.lang.String, int
supplyPuk - boolean: java.lang.String, java.lang.String
supplyPukGemini - boolean: java.lang.String, java.lang.String, int
toString - class java.lang.String: 
toggleRadioOnOff - void: 
transmitIccBasicChannel - class java.lang.String: int, int, int, int, int, java.lang.String
transmitIccBasicChannelGemini - class java.lang.String: int, int, int, int, int, java.lang.String, int
transmitIccLogicalChannel - class java.lang.String: int, int, int, int, int, int, java.lang.String
transmitIccLogicalChannelGemini - class java.lang.String: int, int, int, int, int, int, java.lang.String, int
transmitIccSimIO - class [B: int, int, int, int, int, java.lang.String
transmitIccSimIOGemini - class [B: int, int, int, int, int, java.lang.String, int
uSimAuth - class java.lang.String: java.lang.String, java.lang.String
uSimAuthGemini - class java.lang.String: java.lang.String, java.lang.String, int
unregisterForSimModeChange - void: android.os.IBinder
updateServiceLocation - void: 
updateServiceLocationGemini - void: int
wait - void: 
wait - void: long
wait - void: long, int

And btw it seems both of the sim cards are active at the same time(no need for switching between sim cards) since i can call the phone using both phone numbers without switching the sim card on the phone.

Thanks!

Coppice answered 4/1, 2015 at 15:36 Comment(0)
C
2

Thanks for the answer headuck! I have not tried your solution, but i found my own solution which worked.

It is possible to use a different constructor for the TelephonyManager where you can pass in the sim card slot you want control over:

    MultiSimClass = Class.forName("android.telephony.MultiSimTelephonyManager");

    for (Constructor<?> constructor : MultiSimClass.getConstructors()){
         if (constructor.getParameterTypes().length == 2){
              try {
                   multiSimTelephonyManager1 = constructor.newInstance(context,0);
                   multiSimTelephonyManager2 = constructor.newInstance(context,1);
             }
         }
     }
Coppice answered 6/6, 2015 at 14:23 Comment(6)
Hello roger, did u get the SIM details on dual SIM phone, using the above code snippet?? What is the type of MultiSimClass, multiSimTelephonyManager1 , multiSimTelephonyManager2 ??Hemidemisemiquaver
Hi! The above snippet only gives you a list of the constructors for the MultiSimTelephonyManager class. To get the other methods you can do something like: for (Method method : MultiSimClass.getMethods()){ System.out.println("method name: " + method.getName()); } And to get a list of the parameter types in the method you can do method.getParameterTypes() or getReturnType() for the return type of the method. MultiSimClass is of the type Class and multiSimTelephonyManager of Object.Coppice
Did u try to get the dual sim slots/operators names/IMSI/MSISDN on any android dual sim phone??Hemidemisemiquaver
This is on an android phone yes. I have not tried to get the IMSI/MSISDN.Coppice
Hi. How do you listen for signal strength on the object (multiSimTelephonyManager1) which does not provide any methods? DO you cast TelephonyManager type to it?Noneffective
Method listenMethod= MultiSimClass.getMethod("listen"); listenMethod.invoke(multiSimTelephonyManager1, new PhoneStateListener(), PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);Coppice
M
2

For this particular version of TelephonyManager, instead of using

TelephonyManager.listen (phoneStateListener, state)

which only listens on the default SIM, you may try using 2 instances of your PhoneStateListener, and call

TelephonyManager.listenGemini (phoneStateListener1, state, 0) for the 1st SIM, and

TelephonyManager.listenGemini (phoneStateListener2, state, 1) for the 2nd SIM,

where the third parameter for listenGemini is the SIM number.

Mcnully answered 5/6, 2015 at 12:5 Comment(2)
where is the "listenGemini" from?Angst
"listenGemini" is an internal method name in the particular implementation of TelephonyManager of the device to support dual sim phones - see the method list from the question obtained by reflection. Such interface should be largely obsolete as in 2017, as modern Android supports dual sim natively.Mcnully
C
2

Thanks for the answer headuck! I have not tried your solution, but i found my own solution which worked.

It is possible to use a different constructor for the TelephonyManager where you can pass in the sim card slot you want control over:

    MultiSimClass = Class.forName("android.telephony.MultiSimTelephonyManager");

    for (Constructor<?> constructor : MultiSimClass.getConstructors()){
         if (constructor.getParameterTypes().length == 2){
              try {
                   multiSimTelephonyManager1 = constructor.newInstance(context,0);
                   multiSimTelephonyManager2 = constructor.newInstance(context,1);
             }
         }
     }
Coppice answered 6/6, 2015 at 14:23 Comment(6)
Hello roger, did u get the SIM details on dual SIM phone, using the above code snippet?? What is the type of MultiSimClass, multiSimTelephonyManager1 , multiSimTelephonyManager2 ??Hemidemisemiquaver
Hi! The above snippet only gives you a list of the constructors for the MultiSimTelephonyManager class. To get the other methods you can do something like: for (Method method : MultiSimClass.getMethods()){ System.out.println("method name: " + method.getName()); } And to get a list of the parameter types in the method you can do method.getParameterTypes() or getReturnType() for the return type of the method. MultiSimClass is of the type Class and multiSimTelephonyManager of Object.Coppice
Did u try to get the dual sim slots/operators names/IMSI/MSISDN on any android dual sim phone??Hemidemisemiquaver
This is on an android phone yes. I have not tried to get the IMSI/MSISDN.Coppice
Hi. How do you listen for signal strength on the object (multiSimTelephonyManager1) which does not provide any methods? DO you cast TelephonyManager type to it?Noneffective
Method listenMethod= MultiSimClass.getMethod("listen"); listenMethod.invoke(multiSimTelephonyManager1, new PhoneStateListener(), PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);Coppice
C
2

For fetching the sim signal strength for both the sim we have to use telephony manager

telephonyManager = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager?
            val cellInfos = telephonyManager?.allCellInfo as ArrayList
            val subManager = context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE) as SubscriptionManager?

this will give the list of cell info now through we need to fetch the registered cell info

/* Function to get registered cell info
    *  @param cellinfo - all cell info for sim
    *  @return registered cell info correspond to cell info
    */
    fun getRegisteredCellInfo(cellInfos: MutableList<CellInfo>): ArrayList<CellInfo> {
        val registeredCellInfos = ArrayList<CellInfo>()
        if (cellInfos != null && cellInfos.isNotEmpty()) {
            for (i in cellInfos.indices) {
                if (cellInfos[i].isRegistered) {
                    registeredCellInfos.add(cellInfos[i])
                }
            }
        }
        return registeredCellInfos
    }

Through register cell, you will get the list of sim info which is present in your device Now through this code which I am pasted below, you will get the signal strength according to your network types whether it is gsm, CDMA and LTE. This will also require runtime permission of access phone state and coarse location so please add them accordingly and registered cell info index is the index of sim one and sim two present in the device. Sim one is the 0 index and sim two is 1 index which you have to pass.

(registeredCellInfos.get(registeredCellInfoIndex) is CellInfoWcdma) -> {
                        val cellInfoWcdma = registeredCellInfos.get(registeredCellInfoIndex) as CellInfoWcdma
                        signalStrength = "${cellInfoWcdma.cellSignalStrength.dbm}"
                    }
                    (registeredCellInfos.get(registeredCellInfoIndex) is CellInfoGsm) -> {
                        val cellInfogsm = registeredCellInfos.get(registeredCellInfoIndex) as CellInfoGsm
                        signalStrength = "${cellInfogsm.cellSignalStrength.dbm}"
                    }
                    (registeredCellInfos.get(registeredCellInfoIndex) is CellInfoLte) -> {
                        val cellInfoLte = registeredCellInfos.get(registeredCellInfoIndex) as CellInfoLte
                        signalStrength = "${cellInfoLte.cellSignalStrength.dbm}"
                    }
Club answered 30/10, 2018 at 12:7 Comment(0)
L
0

Here the solution Kotlin Note: Android Pie and above signal will fetch only if location is ON, why i don't know

    fun getRegisteredCellInfo(cellInfos: MutableList<CellInfo>): ArrayList<CellInfo> {
    val registeredCellInfos = ArrayList<CellInfo>()
    if (cellInfos.isNotEmpty()) {
        for (i in cellInfos.indices) {
            if (cellInfos[i].isRegistered) {
                registeredCellInfos.add(cellInfos[i])
            }
        }
    }
    return registeredCellInfos
}


fun getNetworkStrength(): Pair<Int, Int> {

    var strength1 = -1
    var strength2 = -1


    val manager = getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE) as SubscriptionManager


    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {

        val telephonyManager = applicationContext.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager


        if (telephonyManager.allCellInfo != null) {


            val allCellinfo = telephonyManager.allCellInfo
            val activeSubscriptionInfoList = manager.activeSubscriptionInfoList

           val regCellInfo= getRegisteredCellInfo(allCellinfo)

                activeSubscriptionInfoList.forEachIndexed { Subindex, subs ->

                    if (activeSubscriptionInfoList.size >= 2) {

                        if (regCellInfo.size >= 2) {

                            if (subs.simSlotIndex == 0) {

                                if (subs.carrierName != "No service") {


                                    strength1 = when (val info1 = regCellInfo[0]) {
                                        is CellInfoLte -> info1.cellSignalStrength.dbm
                                        is CellInfoGsm -> info1.cellSignalStrength.dbm
                                        is CellInfoCdma -> info1.cellSignalStrength.dbm
                                        is CellInfoWcdma -> info1.cellSignalStrength.dbm
                                        else -> 0
                                    }

                                    Timber.i("subs $subs")

                                    Timber.i("sim1   ${subs.carrierName}  ${subs.mnc}  $strength1")
                                } else {

                                    strength1 = -1
                                }

                            } else if (subs.simSlotIndex == 1) {

                                if (subs.carrierName != "No service") {

                                    strength2 = when (val info2 = regCellInfo[1]) {
                                        is CellInfoLte -> info2.cellSignalStrength.dbm
                                        is CellInfoGsm -> info2.cellSignalStrength.dbm
                                        is CellInfoCdma -> info2.cellSignalStrength.dbm
                                        is CellInfoWcdma -> info2.cellSignalStrength.dbm
                                        else -> 0
                                    }

                                    Timber.i("sim2   ${subs.carrierName}  $strength2")
                                } else {

                                    strength2 = -1
                                }

                            }

                        }
                    }else if(activeSubscriptionInfoList.size == 1)
                    {

                        if(regCellInfo.size >= 1) {

                            if (subs.simSlotIndex == 0) {

                                if (subs.carrierName != "No service") {


                                    strength1 = when (val info1 = regCellInfo[0]) {
                                        is CellInfoLte -> info1.cellSignalStrength.level
                                        is CellInfoGsm -> info1.cellSignalStrength.level
                                        is CellInfoCdma -> info1.cellSignalStrength.level
                                        is CellInfoWcdma -> info1.cellSignalStrength.level
                                        else -> 0
                                    }

                                    Timber.i("subs $subs")

                                    Timber.i("sim1   ${subs.carrierName}  ${subs.mnc}  $strength1")
                                } else {

                                    strength1 = -1
                                }

                            }
                        }

                        strength2 = -2

                    }
                }

            }
        }

    Timber.i("final strenght   sim1 $strength1  sim2 $strength2")

    return Pair(strength1, strength2)
}
Ludicrous answered 8/11, 2019 at 5:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.