I'm trying to identify when the user is not connected to the internet in an app and I find that, when I try to use NetworkInfo for it, the app stops working. It does not give any compilation error, but I know that or what gives the failure is what is in if
based on tests I have done (the problem is that I do not know what the problem is):
public boolean conectado ()
{
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnected())
{
return true;
}
return false;
}
I have already added the permission ACCESS_NETWORK_STATE
in the manifest, but it still does not work.
The following appears in the logcat:
07-12 14:52:00.548 1533-1533/? I/InstallerConnection: connecting...
[ 07-12 14:52:00.549 1300: 1300 I/ ]
new connection
07-12 14:52:00.569 1533-1533/? I/InstallerConnection: disconnecting...
[ 07-12 14:52:00.569 1300: 1300 E/ ]
eof
[ 07-12 14:52:00.569 1300: 1300 E/ ]
failed to read size
[ 07-12 14:52:00.569 1300: 1300 I/ ]
closing connection
07-12 14:52:00.775 1533-1533/? I/InstallerConnection: connecting...
[ 07-12 14:52:00.775 1300: 1300 I/ ]
new connection
07-12 14:52:34.277 1612-1612/? W/RichInputConnection: Slow InputConnection: GET_TEXT_BEFORE_CURSOR took 272 ms.
07-12 14:53:17.757 1533-1533/? W/IInputConnectionWrapper: reportFullscreenMode on inexistent InputConnection
07-12 14:53:21.690 2365-2756/? I/FA-SVC: App measurement is starting up, version: 10298
07-12 14:53:22.310 2365-2825/? I/FA-SVC: This instance being marked as an uploader