2015-10-07 49 views
8

我做了一個網絡監視器應用程序。在這裏我已經成功實施了所有的事情。我有雙卡android手機。我知道如何獲得運營商的名字。但我想知道哪個SIM卡連接到互聯網?我已經使用此代碼,僅向用戶顯示設備通過移動數據連接。我想更具體地說明該設備目前正在使用哪個運營商的互聯網。如何獲取雙SIM卡android手機上連接互聯網的運營商名稱?

public static String isInternetConnected (Context ctx) { 
     ConnectivityManager connectivityMgr = (ConnectivityManager) ctx 
       .getSystemService(CONNECTIVITY_SERVICE); 
     NetworkInfo wifi = connectivityMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI); 
     NetworkInfo mobile = connectivityMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); 
     // Check if wifi or mobile network is available or not. If any of them is 
     // available or connected then it will return true, otherwise false; 
     if (wifi != null) { 
      if (wifi.isConnected()) { 
       return "wifi"; 
      } 
     } 
     if (mobile != null) { 
      if (mobile.isConnected()) { 
       return "mobile"; 
      } 
     } 
     return "none"; 
    } 
+0

你得到解決? –

回答

0

沒有關於多個SIM API 22之前,您可以聯繫您的設備製造商,並檢查他們是否有一個SDK插件訪問多個SIM與否API。

從API 22開始,您可以使用SubscriptionManager的方法getActiveSubscriptionInfoList()檢查多個SIM卡。有關Android文檔的更多詳情。請參閱multiple sims這裏有一些關於多重的討論,希望這可以幫助你找到一種方法來訪問多個SIM卡網絡。

0

檢查這個代碼https://github.com/dragos-niculescu/dualsim/blob/master/src/com/example/dualsim/TelephonyInfo.java

TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); 
int dataNetworkTypeSIM1 = telephonyManager.getNetworkType(); 
int dataNetworkTypeSIM2 = 0; 
try { 
    dataNetworkTypeSIM1 = Integer.parseInt(getStringOfInt(context, "getNetworkTypeGemini", 0)); 
    dataNetworkTypeSIM2 = Integer.parseInt(getStringOfInt(context, "getNetworkTypeGemini", 1)); 
} catch (GeminiMethodNotFoundException e) { 
    try { 
     dataNetworkTypeSIM1 = Integer.parseInt(getStringOfInt(context, "getDataNetworkTypeGemini", 0)); 
     dataNetworkTypeSIM2 = Integer.parseInt(getStringOfInt(context, "getDataNetworkTypeGemini", 1)); 
    } catch (GeminiMethodNotFoundException e1) { 
     try { 
      dataNetworkTypeSIM1 = Integer.parseInt(getStringOfInt(context, "getDataNetworkType", 0)); 
      dataNetworkTypeSIM2 = Integer.parseInt(getStringOfInt(context, "getDataNetworkType", 1)); 
     } catch (GeminiMethodNotFoundException e2) { 
      try { 
        dataNetworkTypeSIM1 = Integer.parseInt(getStringOfInt(context, "getNetworkType", 0)); 
        dataNetworkTypeSIM2 = Integer.parseInt(getStringOfInt(context, "getNetworkType", 1)); 
      } catch (GeminiMethodNotFoundException e3) {} 
     } 
    } 
} 

你可以通過調用得到所有可用的方法:

TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); 
Method[] methods = Class.forName(telephonyManager.getClass().getName()).getMethods(); 
相關問題