get Location Sync Status String - Android Map

Android examples for Map:Location String

Description

get Location Sync Status String

Demo Code


import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;

public class Main{
    public static int TYPE_GPS = 1;
    public static int TYPE_WIFI_NETWORK = 2;
    public static int TYPE_NOT_AVAILABLE = 0;
    public static String getLocationSyncStatusString(Context context) {
        int conn = LocationSyncUtils.getLocationSyncStatus(context);
        String status = null;/*from   w w  w .j a  va  2  s .  c o  m*/
        if (conn == LocationSyncUtils.TYPE_GPS) {
            status = "GPS enabled";
        } else if (conn == LocationSyncUtils.TYPE_WIFI_NETWORK) {
            status = "Mobile Network enabled";
        } else if (conn == LocationSyncUtils.TYPE_NOT_AVAILABLE) {
            status = "Location Sync not available";
        }
        return status;
    }
    public static int getLocationSyncStatus(Context context) {
        LocationManager manager = (LocationManager) context
                .getSystemService(Context.LOCATION_SERVICE);
        if (manager != null) {
            if (manager.isProviderEnabled(LocationManager.GPS_PROVIDER))
                return TYPE_GPS;
            if (manager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
                return TYPE_WIFI_NETWORK;
        }
        return TYPE_NOT_AVAILABLE;
    }
}

Related Tutorials