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

Tus*_*rul 7 android android-networking

我做了一个网络监控应用程序.在这里,我成功地实现了所有的事情.我有双卡通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)

xxx*_*zhi 0

API 22 之前没有关于多卡的 API。您可以联系您的设备制造商并检查他们是否有 SDK 插件来访问多卡。

从 API 22 开始,您可以使用 SubscriptionManager 的方法 getActiveSubscriptionInfoList() 检查多个 SIM。有关 Android 文档的更多详细信息。

请查看多个模拟人生。以下是关于多卡的一些讨论,希望这可以帮助您找到访问多卡网络的方法。