Example usage for android.location LocationManager NETWORK_PROVIDER

List of usage examples for android.location LocationManager NETWORK_PROVIDER

Introduction

In this page you can find the example usage for android.location LocationManager NETWORK_PROVIDER.

Prototype

String NETWORK_PROVIDER

To view the source code for android.location LocationManager NETWORK_PROVIDER.

Click Source Link

Document

Name of the network location provider.

Usage

From source file:uk.org.rivernile.edinburghbustracker.android.fragments.general.NearestStopsFragment.java

/**
 * {@inheritDoc}// ww w. ja v a  2  s  .c  o m
 */
@Override
public void onResume() {
    super.onResume();

    // Start the location providers if they are enabled.
    if (locMan.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
        locMan.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, REQUEST_PERIOD, MIN_DISTANCE, this);
    }

    if (locMan.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        locMan.requestLocationUpdates(LocationManager.GPS_PROVIDER, REQUEST_PERIOD, MIN_DISTANCE, this);
    }
}

From source file:com.android2ee.tileprovider.activity.MainActivity.java

@Override
protected void onResume() {
    super.onResume();
    // maybe change the provider
    if (locationManager != null) {
        Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        if (location != null) {
            updateMarker(location);//w  w w .j a  v  a2  s .c  om
        }
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 0, this);
    }
}

From source file:io.kristal.locationplugin.LocationPlugin.java

/***********************************************************************************************
 *
 * METHODS//from   w ww.java 2 s. c o m
 *
 **********************************************************************************************/

private void getActiveProviders(Context context) {
    mProviders = new ArrayList<>();

    mLocationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    if (mLocationManager.isProviderEnabled(LocationManager.PASSIVE_PROVIDER)) {
        mProviders.add(LocationManager.PASSIVE_PROVIDER);
    }
    if (mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
        mProviders.add(LocationManager.NETWORK_PROVIDER);
    }
    if (mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        mProviders.add(LocationManager.GPS_PROVIDER);
    }
}

From source file:org.openchaos.android.fooping.service.PingService.java

@Override
protected void onHandleIntent(Intent intent) {
    String clientID = prefs.getString("ClientID", "unknown");
    long ts = System.currentTimeMillis();

    Log.d(tag, "onHandleIntent()");

    // always send ping
    if (true) {/*from   w  w  w  .  j av a2  s  .c om*/
        try {
            JSONObject json = new JSONObject();
            json.put("client", clientID);
            json.put("type", "ping");
            json.put("ts", ts);

            sendMessage(json);
        } catch (Exception e) {
            Log.e(tag, e.toString());
            e.printStackTrace();
        }
    }

    // http://developer.android.com/training/monitoring-device-state/battery-monitoring.html
    // http://developer.android.com/reference/android/os/BatteryManager.html
    if (prefs.getBoolean("UseBattery", false)) {
        try {
            JSONObject json = new JSONObject();
            json.put("client", clientID);
            json.put("type", "battery");
            json.put("ts", ts);

            Intent batteryStatus = registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
            if (batteryStatus != null) {
                JSONObject bat_data = new JSONObject();

                int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
                int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
                if (level >= 0 && scale > 0) {
                    bat_data.put("pct", roundValue(((double) level / (double) scale) * 100, 2));
                } else {
                    Log.w(tag, "Battery level unknown");
                    bat_data.put("pct", -1);
                }
                bat_data.put("health", batteryStatus.getIntExtra(BatteryManager.EXTRA_HEALTH, -1));
                bat_data.put("status", batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1));
                bat_data.put("plug", batteryStatus.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1));
                bat_data.put("volt", batteryStatus.getIntExtra(BatteryManager.EXTRA_VOLTAGE, -1));
                bat_data.put("temp", batteryStatus.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, -1));
                bat_data.put("tech", batteryStatus.getStringExtra(BatteryManager.EXTRA_TECHNOLOGY));
                // bat_data.put("present", batteryStatus.getBooleanExtra(BatteryManager.EXTRA_PRESENT, false));

                json.put("battery", bat_data);
            }

            sendMessage(json);
        } catch (Exception e) {
            Log.e(tag, e.toString());
            e.printStackTrace();
        }
    }

    // http://developer.android.com/guide/topics/location/strategies.html
    // http://developer.android.com/reference/android/location/LocationManager.html
    if (prefs.getBoolean("UseGPS", false)) {
        try {
            JSONObject json = new JSONObject();
            json.put("client", clientID);
            json.put("type", "loc_gps");
            json.put("ts", ts);

            if (lm == null) {
                lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
            }

            Location last_loc = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
            if (last_loc != null) {
                JSONObject loc_data = new JSONObject();

                loc_data.put("ts", last_loc.getTime());
                loc_data.put("lat", last_loc.getLatitude());
                loc_data.put("lon", last_loc.getLongitude());
                if (last_loc.hasAltitude())
                    loc_data.put("alt", roundValue(last_loc.getAltitude(), 4));
                if (last_loc.hasAccuracy())
                    loc_data.put("acc", roundValue(last_loc.getAccuracy(), 4));
                if (last_loc.hasSpeed())
                    loc_data.put("speed", roundValue(last_loc.getSpeed(), 4));
                if (last_loc.hasBearing())
                    loc_data.put("bearing", roundValue(last_loc.getBearing(), 4));

                json.put("loc_gps", loc_data);
            }

            sendMessage(json);
        } catch (Exception e) {
            Log.e(tag, e.toString());
            e.printStackTrace();
        }
    }

    if (prefs.getBoolean("UseNetwork", false)) {
        try {
            JSONObject json = new JSONObject();
            json.put("client", clientID);
            json.put("type", "loc_net");
            json.put("ts", ts);

            if (lm == null) {
                lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
            }

            Location last_loc = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
            if (last_loc != null) {
                JSONObject loc_data = new JSONObject();

                loc_data.put("ts", last_loc.getTime());
                loc_data.put("lat", last_loc.getLatitude());
                loc_data.put("lon", last_loc.getLongitude());
                if (last_loc.hasAltitude())
                    loc_data.put("alt", roundValue(last_loc.getAltitude(), 4));
                if (last_loc.hasAccuracy())
                    loc_data.put("acc", roundValue(last_loc.getAccuracy(), 4));
                if (last_loc.hasSpeed())
                    loc_data.put("speed", roundValue(last_loc.getSpeed(), 4));
                if (last_loc.hasBearing())
                    loc_data.put("bearing", roundValue(last_loc.getBearing(), 4));

                json.put("loc_net", loc_data);
            }

            sendMessage(json);
        } catch (Exception e) {
            Log.e(tag, e.toString());
            e.printStackTrace();
        }
    }

    // http://developer.android.com/reference/android/net/wifi/WifiManager.html
    if (prefs.getBoolean("UseWIFI", false)) {
        try {
            JSONObject json = new JSONObject();
            json.put("client", clientID);
            json.put("type", "wifi");
            json.put("ts", ts);

            if (wm == null) {
                wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
            }

            List<ScanResult> wifiScan = wm.getScanResults();
            if (wifiScan != null) {
                JSONArray wifi_list = new JSONArray();

                for (ScanResult wifi : wifiScan) {
                    JSONObject wifi_data = new JSONObject();

                    wifi_data.put("BSSID", wifi.BSSID);
                    wifi_data.put("SSID", wifi.SSID);
                    wifi_data.put("freq", wifi.frequency);
                    wifi_data.put("level", wifi.level);
                    // wifi_data.put("cap", wifi.capabilities);
                    // wifi_data.put("ts", wifi.timestamp);

                    wifi_list.put(wifi_data);
                }

                json.put("wifi", wifi_list);
            }

            sendMessage(json);
        } catch (Exception e) {
            Log.e(tag, e.toString());
            e.printStackTrace();
        }
    }

    // TODO: cannot poll sensors. register receiver to cache sensor data
    // http://developer.android.com/guide/topics/sensors/sensors_overview.html
    // http://developer.android.com/reference/android/hardware/SensorManager.html
    if (prefs.getBoolean("UseSensors", false)) {
        try {
            JSONObject json = new JSONObject();
            json.put("client", clientID);
            json.put("type", "sensors");
            json.put("ts", ts);

            if (sm == null) {
                sm = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
            }

            List<Sensor> sensors = sm.getSensorList(Sensor.TYPE_ALL);
            if (sensors != null) {
                JSONArray sensor_list = new JSONArray();

                for (Sensor sensor : sensors) {
                    JSONObject sensor_info = new JSONObject();

                    sensor_info.put("name", sensor.getName());
                    sensor_info.put("type", sensor.getType());
                    sensor_info.put("vendor", sensor.getVendor());
                    sensor_info.put("version", sensor.getVersion());
                    sensor_info.put("power", roundValue(sensor.getPower(), 4));
                    sensor_info.put("resolution", roundValue(sensor.getResolution(), 4));
                    sensor_info.put("range", roundValue(sensor.getMaximumRange(), 4));

                    sensor_list.put(sensor_info);
                }

                json.put("sensors", sensor_list);
            }

            sendMessage(json);
        } catch (Exception e) {
            Log.e(tag, e.toString());
            e.printStackTrace();
        }
    }

    // http://developer.android.com/training/monitoring-device-state/connectivity-monitoring.html
    // http://developer.android.com/reference/android/net/ConnectivityManager.html
    if (prefs.getBoolean("UseConn", false)) {
        try {
            JSONObject json = new JSONObject();
            json.put("client", clientID);
            json.put("type", "conn");
            json.put("ts", ts);

            if (cm == null) {
                cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
            }

            // TODO: add active/all preferences below UseConn
            if (prefs.getBoolean("UseConnActive", true)) {
                NetworkInfo net = cm.getActiveNetworkInfo();
                if (net != null) {
                    JSONObject net_data = new JSONObject();

                    net_data.put("type", net.getTypeName());
                    net_data.put("subtype", net.getSubtypeName());
                    net_data.put("connected", net.isConnected());
                    net_data.put("available", net.isAvailable());
                    net_data.put("roaming", net.isRoaming());
                    net_data.put("failover", net.isFailover());
                    if (net.getReason() != null)
                        net_data.put("reason", net.getReason());
                    if (net.getExtraInfo() != null)
                        net_data.put("extra", net.getExtraInfo());

                    json.put("conn_active", net_data);
                }
            }

            if (prefs.getBoolean("UseConnAll", false)) {
                NetworkInfo[] nets = cm.getAllNetworkInfo();
                if (nets != null) {
                    JSONArray net_list = new JSONArray();

                    for (NetworkInfo net : nets) {
                        JSONObject net_data = new JSONObject();

                        net_data.put("type", net.getTypeName());
                        net_data.put("subtype", net.getSubtypeName());
                        net_data.put("connected", net.isConnected());
                        net_data.put("available", net.isAvailable());
                        net_data.put("roaming", net.isRoaming());
                        net_data.put("failover", net.isFailover());
                        if (net.getReason() != null)
                            net_data.put("reason", net.getReason());
                        if (net.getExtraInfo() != null)
                            net_data.put("extra", net.getExtraInfo());

                        net_list.put(net_data);
                    }

                    json.put("conn_all", net_list);
                }
            }

            sendMessage(json);
        } catch (Exception e) {
            Log.e(tag, e.toString());
            e.printStackTrace();
        }
    }

    if (!PingServiceReceiver.completeWakefulIntent(intent)) {
        Log.w(tag, "completeWakefulIntent() failed. no active wake lock?");
    }
}

From source file:net.fabiszewski.ulogger.LoggerService.java

/**
 * Request location updates//from  w  w  w .j ava  2 s . co m
 * @return True if succeeded from at least one provider
 */
private boolean requestLocationUpdates() {
    boolean hasLocationUpdates = false;
    if (canAccessLocation()) {
        if (useNet) {
            //noinspection MissingPermission
            locManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, minTimeMillis, minDistance,
                    locListener, looper);
            if (locManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
                hasLocationUpdates = true;
                if (Logger.DEBUG) {
                    Log.d(TAG, "[Using net provider]");
                }
            }
        }
        if (useGps) {
            //noinspection MissingPermission
            locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, minTimeMillis, minDistance,
                    locListener, looper);
            if (locManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
                hasLocationUpdates = true;
                if (Logger.DEBUG) {
                    Log.d(TAG, "[Using gps provider]");
                }
            }
        }
        if (!hasLocationUpdates) {
            // no location provider available
            sendBroadcast(BROADCAST_LOCATION_DISABLED);
            if (Logger.DEBUG) {
                Log.d(TAG, "[No available location updates]");
            }
        }
    } else {
        // can't access location
        sendBroadcast(BROADCAST_LOCATION_PERMISSION_DENIED);
        if (Logger.DEBUG) {
            Log.d(TAG, "[Location permission denied]");
        }
    }

    return hasLocationUpdates;
}

From source file:com.vrjco.v.demo.MainActivity.java

private void setTestCoordinate() {
    //checking if gps and network is ON.
    gpsok = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
    networkok = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
    if (ActivityCompat.checkSelfPermission(this,
            Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(this,
                    Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        Toast.makeText(this, "LOCATION PROVIDER PERMISSIONS NOT GRANTED", Toast.LENGTH_LONG).show();
        return;/*  w w  w. j  a  v a2s  .c  o  m*/
    }
    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 1000 * 60, testLocationListener);
    lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 1000 * 60, testLocationListener);
    if (gpsok && networkok) {
        Toast.makeText(this, "GPS and NETWORK PROVIDER Found!!", Toast.LENGTH_SHORT).show();
        location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        location = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        if (location != null) {
            test_lat = location.getLatitude();
            test_longi = location.getLongitude();
            tvtestlat.setText(Double.toString(test_lat));
            tvtestlongi.setText(Double.toString(test_longi));
            test_is_set = true;
        }

    } else {
        Toast.makeText(this, "LOCATION PROVIDER NOT AVAILABLE", Toast.LENGTH_LONG).show();
        test_is_set = false;
    }

    lm.removeUpdates(testLocationListener);
}

From source file:com.sitewhere.android.example.ExampleFragment.java

/**
 * Only schedule SiteWhere reporting thread once we have a connection to the server.
 *///from   w w w  .  j av  a2 s  .c om
public void startDeviceMonitoring() {
    Log.d(TAG, "Starting device monitoring.");

    getActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {
            // Start location updates.
            boolean locationStarted = false;
            locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
            if (ActivityCompat.checkSelfPermission(getActivity(),
                    Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
                    && ActivityCompat.checkSelfPermission(getActivity(),
                            Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                Log.d(TAG, "No permissions for location. Requesting permissions from user.");
                requestPermissions(new String[] { Manifest.permission.ACCESS_FINE_LOCATION,
                        Manifest.permission.ACCESS_COARSE_LOCATION }, LOCATION_REQUEST_CODE);
                return;
            }
            if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
                locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
                        ExampleFragment.this);
                locationStarted = true;
                Log.d(TAG, "Started monitoring locations via GPS provider.");
            } else if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
                locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0,
                        ExampleFragment.this);
                locationStarted = true;
                Log.d(TAG, "Started monitoring locations via network provider.");
            } else {
                locationStarted = false;
                Log.d(TAG, "No location provider available. Will not monitor location.");
            }

            // Start accelerometer updates.
            boolean accelerometerStarted = false;
            sensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE);
            if (sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) != null) {
                rotationVector = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
                sensorManager.registerListener(ExampleFragment.this, rotationVector,
                        SensorManager.SENSOR_DELAY_NORMAL);
                accelerometerStarted = true;
                Log.d(TAG, "Started monitoring accelerometer.");
            } else {
                Toast.makeText(getActivity().getApplicationContext(),
                        "Unable to start accelerometer updates. No accelerometer provided", Toast.LENGTH_LONG);
                accelerometerStarted = false;
                Log.d(TAG, "Unable to monitor accelerometer.");
            }

            // Send alerts to SiteWhere.
            SiteWhereMessageClient messageClient = SiteWhereMessageClient.getInstance();
            try {
                if (locationStarted)
                    messageClient.sendDeviceAlert(messageClient.getUniqueDeviceId(), "location.started",
                            "Started to read location data.", null);
            } catch (SiteWhereMessagingException ex) {
                Log.e(TAG, "Unable to send location.started alert to SiteWhere.");
            }
            try {
                if (accelerometerStarted)
                    messageClient.sendDeviceAlert(messageClient.getUniqueDeviceId(), "accelerometer.started",
                            "Started to read accelerometer data.", null);
            } catch (SiteWhereMessagingException e) {
                Log.e(TAG, "Unable to send accelerometer.started alert to SiteWhere.");
            }

            if (scheduler != null) {
                scheduler.shutdownNow();
            }
            scheduler = Executors.newSingleThreadScheduledExecutor();
            scheduler.scheduleAtFixedRate(new SiteWhereDataReporter(), SEND_INTERVAL_IN_SECONDS,
                    SEND_INTERVAL_IN_SECONDS, TimeUnit.SECONDS);
            Log.d(TAG, "Set up scheduler for monitoring.");
        }
    });
}

From source file:org.metawatch.manager.Monitors.java

public static void start(Context context, TelephonyManager telephonyManager) {
    // start weather updater

    if (Preferences.logging)
        Log.d(MetaWatch.TAG, "Monitors.start()");

    createBatteryLevelReciever(context);
    createWifiReceiver(context);/*from   ww w .  j  a  va  2 s  .  co m*/

    if (Preferences.weatherGeolocation) {
        if (Preferences.logging)
            Log.d(MetaWatch.TAG, "Initialising Geolocation");

        try {
            locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
            locationProvider = LocationManager.NETWORK_PROVIDER;

            networkLocationListener = new NetworkLocationListener(context);

            locationManager.requestLocationUpdates(locationProvider, 30 * 60 * 1000, 500,
                    networkLocationListener);

            RefreshLocation();
        } catch (IllegalArgumentException e) {
            if (Preferences.logging)
                Log.d(MetaWatch.TAG, "Failed to initialise Geolocation " + e.getMessage());
        }
    } else {
        if (Preferences.logging)
            Log.d(MetaWatch.TAG, "Geolocation disabled");
    }

    CallStateListener phoneListener = new CallStateListener(context);

    telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    int phoneEvents = PhoneStateListener.LISTEN_CALL_STATE | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS
            | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE;
    telephonyManager.listen(phoneListener, phoneEvents);

    if (Utils.isGmailAccessSupported(context)) {
        gmailMonitor = new GmailMonitor(context);
        gmailMonitor.startMonitor();
    }

    try {
        contentObserverMessages = new ContentObserverMessages(context);
        Uri uri = Uri.parse("content://mms-sms/conversations/");
        contentResolverMessages = context.getContentResolver();
        contentResolverMessages.registerContentObserver(uri, true, contentObserverMessages);
    } catch (Exception x) {
    }

    try {
        contentObserverCalls = new ContentObserverCalls(context);
        //Uri uri = Uri.parse("content://mms-sms/conversations/");
        contentResolverCalls = context.getContentResolver();
        contentResolverCalls.registerContentObserver(android.provider.CallLog.Calls.CONTENT_URI, true,
                contentObserverCalls);
    } catch (Exception x) {
    }

    try {
        contentObserverAppointments = new ContentObserverAppointments(context);
        Uri uri = Uri.parse("content://com.android.calendar/calendars/");
        contentResolverAppointments = context.getContentResolver();
        contentResolverAppointments.registerContentObserver(uri, true, contentObserverAppointments);
    } catch (Exception x) {
    }

    // temporary one time update
    updateWeatherData(context);

    startAlarmTicker(context);
}

From source file:ca.rmen.android.networkmonitor.app.prefs.PreferenceFragmentActivity.java

/**
 * Checks if we have either the GPS or Network location provider enabled. If not, shows a popup dialog telling the user they should go to the system
 * settings to enable location tracking.
 */// w ww. jav  a2s  . co  m
private void checkLocationSettings() {
    // If the user chose high accuracy, make sure we have at least one location provider.
    LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    if (!(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
            || locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))) {
        DialogFragmentFactory.showConfirmDialog(this, getString(R.string.no_location_confirm_dialog_title),
                getString(R.string.no_location_confirm_dialog_message), ID_ACTION_LOCATION_SETTINGS, null);
    } else {
        finish();
    }
}

From source file:org.example.xwalkembedded.LocationActivity.java

private void setup() {
    Location gpsLocation = null;/*  ww w.j  av a 2s  . com*/
    Location networkLocation = null;
    try {
        mLocationManager.removeUpdates(listener);
    } catch (SecurityException e) {
        e.printStackTrace();
    }
    mLatLng.setText(R.string.unknown);
    mAddress.setText(R.string.unknown);
    // Get fine location updates only.
    if (mUseFine) {
        mFineProviderButton.setBackgroundResource(R.drawable.button_active);
        mBothProviderButton.setBackgroundResource(R.drawable.button_inactive);
        // Request updates from just the fine (gps) provider.
        gpsLocation = requestUpdatesFromProvider(LocationManager.GPS_PROVIDER, R.string.not_support_gps);
        // Update the UI immediately if a location is obtained.
        if (gpsLocation != null)
            updateUILocation(gpsLocation);
    } else if (mUseBoth) {
        // Get coarse and fine location updates.
        mFineProviderButton.setBackgroundResource(R.drawable.button_inactive);
        mBothProviderButton.setBackgroundResource(R.drawable.button_active);
        // Request updates from both fine (gps) and coarse (network) providers.
        gpsLocation = requestUpdatesFromProvider(LocationManager.GPS_PROVIDER, R.string.not_support_gps);
        networkLocation = requestUpdatesFromProvider(LocationManager.NETWORK_PROVIDER,
                R.string.not_support_network);

        // If both providers return last known locations, compare the two and use the better
        // one to update the UI.  If only one provider returns a location, use it.
        if (gpsLocation != null && networkLocation != null) {
            updateUILocation(getBetterLocation(gpsLocation, networkLocation));
            Log.d("fujunwei", "======getBetterLocation ");
        } else if (gpsLocation != null) {
            Log.d("fujunwei", "======gpsLocation ");
            updateUILocation(gpsLocation);
        } else if (networkLocation != null) {
            Log.d("fujunwei", "======networkLocation ");
            updateUILocation(networkLocation);
        }
        //            requestPermissionsForLocation();
        Log.d("fujunwei", "======All null ");
    }
}