【发布时间】:2017-08-08 17:17:58
【问题描述】:
我正在构建一个网络监视器应用程序。在这里,我已经成功实现了所有功能,例如跟踪 Wifi 或移动数据的数据使用情况,但我想知道哪个 SIM 连接到互联网并使用移动数据。
使用下面的代码,我可以知道我的双卡手机是否连接到 Wifi 或移动数据。
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";
}
如何获取双卡安卓手机中消耗移动数据的 SIM 索引或 SIM 运营商名称?
我搜索了很多,我看到很多问题都发布在 SO 中,但没有答案,例如 this。
我能够在双 SIM 卡手机中获取两个 SIM 卡的子 ID,但我正在逐步解决问题,以了解哪个 SIM 卡正在使用互联网。
许多其他应用程序都能够像 Mubble 一样做到这一点。
谁能给我一个解决方案?
【问题讨论】:
标签: android operating-system android-networking internet-connection dual-sim