Any alternative way to check if network location provider is enabled?

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?

Answer

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());
}

Leave a Reply

Your email address will not be published. Required fields are marked *