I\'m having this problem on some 2013 Nexus 7\'s.
got some code to work (please see below).
package acme.wifi;
import android.content.*;
import and
I think need to add Network State Access
permission in AndroidManifest.xml
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Add permission in the manifest file:
android.permission.ACCESS_FINE_LOCATION
android.permission.ACCESS_COARSE_LOCATION
I have same issue with 5.1.1 and Try to ping server of google.com like:
public Boolean isOnline() {
try {
// Process p1 = runtime.exec("/system/bin/ping -c 1 8.8.8.8");
Process p1 = java.lang.Runtime.getRuntime().exec("ping -c 1 www.google.com");
int returnVal = p1.waitFor();
boolean reachable = (returnVal==0);
return reachable;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}
this will give you correct response.
The new code in the question seems to work.
4/16 now the code has stopped working :(
I was facing the same problem, but I have solved it.
Add these permissions:
android.permission.ACCESS_FINE_LOCATION
android.permission.ACCESS_COARSE_LOCATION
and Keep Location Service ON.
Strange but true.