Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 471
DixieFlatline Avatar asked Nov 02 '11 18:11

DixieFlatline


1 Answers

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());
}
like image 133
Yilmaz Guleryuz Avatar answered Sep 27 '22 23:09

Yilmaz Guleryuz