Reputation: 8035
When i check
boolean networkReady=manager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
i get true on some Samsung phones, eventhough the wireless location is not allowed in settings.
Is there any other way to check this setting and to get the correct value on all phones?
Upvotes: 5
Views: 1253
Reputation: 24021
You can also try like this:
public boolean isDataConnectionAvailable(Context context){
ConnectivityManager connectivityManager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = connectivityManager.getActiveNetworkInfo();
if(info == null)
return false;
return connectivityManager.getActiveNetworkInfo().isConnected();
}
public boolean isGpsEnabled(LocationManager manager){
if ( !manager.isProviderEnabled( LocationManager.GPS_PROVIDER ) ) {
return false;
}
return true;
}
public boolean isLocationByNetworkEnabled(LocationManager manager){
if ( !manager.isProviderEnabled( LocationManager.NETWORK_PROVIDER ) ) {
return false;
}
return true;
}
Upvotes: 3
Reputation: 10938
Is the provider in the list returned by getProviders(true); as well? Perhaps that device thinks that the network location provider should always be enabled to provide a PASSIVE_PROVIDER? Seems broken to me. Which Samsung devices do you see this behaviour on?
Upvotes: 0
Reputation: 9735
Attached below some nice network util functions I've been using across my apps, all works like a charm! and for location polling, definitely -> https://github.com/commonsguy/cwac-locpoll
hope this helps...
public static boolean checkInternetConnection(Context context) {
ConnectivityManager conMgr = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
// ARE WE CONNECTED TO THE NET?
if (conMgr.getActiveNetworkInfo() != null
&& conMgr.getActiveNetworkInfo().isAvailable()
&& conMgr.getActiveNetworkInfo().isConnected()) {
return true;
} else {
Log.w(TAG, "Internet Connection NOT Present");
return false;
}
}
public static boolean isConnAvailAndNotRoaming(Context context) {
ConnectivityManager conMgr = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (conMgr.getActiveNetworkInfo() != null
&& conMgr.getActiveNetworkInfo().isAvailable()
&& conMgr.getActiveNetworkInfo().isConnected()) {
if(!conMgr.getActiveNetworkInfo().isRoaming())
return true;
else
return false;
} else {
Log.w(TAG, "Internet Connection NOT Present");
return false;
}
}
public static boolean isRoaming(Context context) {
ConnectivityManager conMgr = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
return (conMgr.getActiveNetworkInfo()!=null && conMgr.getActiveNetworkInfo().isRoaming());
}
Upvotes: 7