1

我正在构建一个需要“getSimOperator”值的android应用程序。

我能够获得此值 > 21 API 版本,但对于双 SIM 卡中的较低版本。我得到 SIM1 的值,但无法获得 SIM2 的值。

如何获得 SIM2 < 21 API 版本的“getSimOperator”值。

我之前在下面发布了一个问题,链接 How to get Mcc and Mnc below LOLLIPOP_MR1

有人向我推荐了一个链接双卡安卓手机,它可以接听电话

但是在实现上述链接的代码时出现错误。我列出了错误“java.lang.NoSuchMethodException:getDefault [int]”

云任何人都向我解释了为什么会出现此错误。

4

1 回答 1

2

在这里,此链接可能会对您有所帮助并参考示例编号。24 在这个例子中http://www.programcreek.com/java-api-examples/android.telephony.TelephonyManager

试试这个 Github 链接。 https://github.com/illarionov/MozStumbler/blob/develop/src/org/mozilla/mozstumbler/cellscanner/GeminiCellScanner.java

在以下方法中,返回可用 SIM 卡的所有信息。

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

另一种方法也是如下。对于 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();
    } 
}

在 AndroidManifest 添加权限:

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

要获得网络运营商,您可以检查 mcc 和 mnc 代码:

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-

于 2016-12-05T11:52:21.600 回答