相关疑难解决方法(0)

如何在双卡安卓手机中获取连接到互联网的运营商名称?

我做了一个网络监控应用程序.在这里,我成功地实现了所有的事情.我有双卡通android手机.我知道如何获得运营商的名称.但我想知道哪个SIM连接到互联网?我使用过此代码,仅向用户显示设备是通过移动数据连接的.我想更具体地说,该设备目前正在使用哪个运营商的互联网.

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";
    }
Run Code Online (Sandbox Code Playgroud)

android android-networking

7
推荐指数
1
解决办法
1306
查看次数

标签 统计

android ×1

android-networking ×1