2015-10-07 11 views
8

Ho creato un'app di monitoraggio di rete. Qui ho implementato con successo tutte le cose. Ho il doppio telefono Android sim. So come ottenere il nome dell'operatore. Ma voglio quello che sim è connesso ad internet? Ho usato questo codice, solo per mostrare all'utente che il dispositivo è connesso tramite dati mobili. Voglio essere più specifico sul fatto che il dispositivo stia attualmente utilizzando quale internet dell'operatore.Come ottenere il nome dell'operatore che è collegato ad internet in un telefono Android sim doppio?

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

sei arrivato la soluzione? –

risposta

0

Non ci sono alcuna API su più Sim prima API 22. È possibile contattare il produttore del dispositivo e controllare se hanno uno SDK add-on per accedere a più Sim o meno.

Dopo l'API 22, è possibile verificare più SIM utilizzando il metodo SubscriptionManager getActiveSubscriptionInfoList(). Maggiori dettagli su Android Docs.

Si prega di guardare multiple sims. Ecco alcune discussioni sul multiplo, spero che questo possa aiutarti a trovare un modo per accedere a più reti sim.

0

controllare questo codice 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) {} 
     } 
    } 
} 

È possibile ottenere tutti i metodi disponibili chiamando il numero:

TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); 
Method[] methods = Class.forName(telephonyManager.getClass().getName()).getMethods(); 
Problemi correlati