2016-12-05 106 views
0

我正在构建一个android应用程序,我需要“getSimOperator”的值。如何在双SIM卡手机android中获取SIMOperator?

我能够得到这个值> 21 API版本,但在双SIM中的较低版本。我获得了SIM1的值,但无法获得SIM2值。

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

我之前发布的一个问题是链接 How to get Mcc and Mnc below LOLLIPOP_MR1

有人向我推荐了一个链接dual sim android phone which sim receive a call

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

云任何人都解释了为什么这个错误即将到来。

+0

这意味着该方法不可用您的手机 – eriuzo

+0

@eriuzo我也在使用它,并尝试在很多设备上,但不适合我。每部手机都有同样的错误。 –

回答

0

这里这个链接可能会帮助你,并引用示例没有。 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

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

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-

+0

我认为SIM1只适用于SIM2 –

+0

谢谢,我会尽快检查并更新您的@Dharmishttha –

+0

我使用您的代码,但仍获得SIM1而非SIM2的MCC和MNC值。如何获得SIM卡的MCC和MNC –

相关问题