2016-12-05 93 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 –

相關問題