How to get the name of operator which is connected to internet in dual sim android phone?

穿精又带淫゛_ 提交于 2019-12-07 01:40:33

问题


I have made a network monitor app. Here I have successfully implemented all the things. I have the dual sim android phone. I know how to get the name of operator. But I want to that which sim is connected to internet? I have used this code, only to show user that the device is connected through mobile data. I want to be more specific that the device is currently using which operator's internet.

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";
    }

回答1:


There are no API about multiple sims before API 22. You can contact your device manufacturer and check whether they have an SDK add-on to access multiple sims or not.

Since API 22, you can check for multiple SIMs using SubscriptionManager's method getActiveSubscriptionInfoList(). More details on Android Docs.

Please look multiple sims. Here are some discussion about multiple, Hope this can help you for finding a way to access multiple sim network.




回答2:


Check this code 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) {}
        }
    }
}

You can get all available methods by calling:

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


来源:https://stackoverflow.com/questions/32993283/how-to-get-the-name-of-operator-which-is-connected-to-internet-in-dual-sim-andro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!