Hitesh Matnani
Hitesh Matnani

Reputation: 329

How to getSimOperator in dual SIM phone android?

I am building an android application where I need a value of "getSimOperator".

I am able to get this value > 21 API version but for the lower version in dual SIM. I am getting a value of SIM1 but not able to get SIM2 value.

How can I get "getSimOperator" value of SIM2 < 21 API version.

I earlier posted a question below is the link How to get Mcc and Mnc below LOLLIPOP_MR1.

Someone has referred me a link dual sim android phone which sim receive a call.

But I am getting an error while implementing the code of above link. I had listed down the error "java.lang.NoSuchMethodException: getDefault [int]"

Cloud anyone explains me why this error is coming.

Upvotes: 1

Views: 2010

Answers (1)

Dharmishtha
Dharmishtha

Reputation: 1343

here this link will might help you and refer the example no. 24 in this example http://www.programcreek.com/java-api-examples/android.telephony.TelephonyManager

Try this Github link. https://github.com/illarionov/MozStumbler/blob/develop/src/org/mozilla/mozstumbler/cellscanner/GeminiCellScanner.java

In this following method return all info for available simcard.

 private List<CellInfo> getCellInfo(int presentSimNumsIndex){}

Another method is also which is as below. For API >=17:

TelephonyManager manager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);

// Get information about all radio modules on device board
// and check what you need by calling #getCellIdentity.

final List<CellInfo> allCellInfo = manager.getAllCellInfo();
for (CellInfo cellInfo : allCellInfo) {
    if (cellInfo instanceof CellInfoGsm) {
         CellIdentityGsm cellIdentity = ((CellInfoGsm) cellInfo).getCellIdentity();
        //TODO Use cellIdentity to check MCC/MNC code, for instance.
    } else if (cellInfo instanceof CellInfoWcdma) {
        CellIdentityWcdma cellIdentity = ((CellInfoWcdma) cellInfo).getCellIdentity();
    } else if (cellInfo instanceof CellInfoLte) {
        CellIdentityLte cellIdentity = ((CellInfoLte) cellInfo).getCellIdentity();
    } else if (cellInfo instanceof CellInfoCdma) {
        CellIdentityCdma cellIdentity = ((CellInfoCdma) cellInfo).getCellIdentity();
    } 
}

In AndroidManifest add permission:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
     <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
</manifest>

To get network operator you can check mcc and mnc codes:

https://en.wikipedia.org/wiki/Mobile_country_code

https://clients.txtnation.com/hc/en-us/articles/218719768-MCCMNC-mobile-country-code-and-mobile-network-code-list-

Upvotes: 2

Related Questions