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