我已经制作了一个网络监控应用程序。在这里,我已经成功地实现了所有的功能。我使用的是双卡安卓手机。我知道如何获取运营商的名称。但是我想知道哪张 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";
}