I want to find is this mobile connected with internet or not(wifi and mobile data) iam using below code its working fine in all device except one mi note 4 i find an issue its not showing false when its not coonected with internet please help me.
public class ConnectionDetector {
private Context _context;
public ConnectionDetector(Context context)
{
this._context = context;
}
public boolean isConnectingToInternet()
{
ConnectivityManager connectivity = (ConnectivityManager) _context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity != null)
{
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null) {
for (int i = 0; i < info.length; i++)
if (info[i].getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
}
return false;
}
}
ConnectionDetector cd = new ConnectionDetector(ViewOrder.this);
Boolean isInternetPresent = cd.isConnectingToInternet();
if (isInternetPresent) {
// its giving true when its in offline only in mi note 4 device. all the mobiles which i checked its working fine
}
else {
}