Example usage for android.location LocationManager GPS_PROVIDER

List of usage examples for android.location LocationManager GPS_PROVIDER

Introduction

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

Prototype

String GPS_PROVIDER

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

Click Source Link

Document

Name of the GPS location provider.

Usage

From source file:activities.GatewayActivity.java

@Override
public void locationMode(boolean on) {
    LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    boolean gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
    boolean networkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
    if (on) {/*from   w w w .j a v  a2 s.c o  m*/
        if (!gpsEnabled || !networkEnabled) {
            new LocationDialog().show(getSupportFragmentManager(), "locationdialog");
            configFragment.updateLocationView(false);
            sApp.isLocationOn = false;
        } else {
            if (!sApp.locationService.isRunning())
                sApp.locationService.start();
            sApp.isLocationOn = true;
            showToast(getString(R.string.location_enabled));
        }
    } else {
        if (sApp.locationService.isRunning())
            sApp.locationService.stop();
        showToast(getString(R.string.toast_stopped_location_service));
        sApp.isLocationOn = false;
    }
    configFragment.updateLocationView(sApp.isLocationOn);
}

From source file:br.com.rescue_bots_android.bluetooth.MainActivity.java

public void initGPSListener() {
    // create class object
    gps = new GPSTrackerImplementation(this);
    // check if GPS enabled     
    if (gps.canGetLocation()) {
        String locationText = getLocationText(gps.getLocation());
        if (locationText != null) {
            Log.i("INFO", locationText);
        } else {//from   w w  w . j a v  a  2 s .com
            Log.i("INFO", "Sem coordenada");
        }
    } else {
        // can't get location
        // GPS or Network is not enabled
        // Ask user to enable GPS/network in settings
        gps.showSettingsAlert();
    }
    if (mBtnClearInput.getText().toString().equalsIgnoreCase(LocationManager.GPS_PROVIDER)) {
        mBtnClearInput.setText(LocationManager.NETWORK_PROVIDER);
        gps.setProvider(LocationManager.NETWORK_PROVIDER);
    } else {
        mBtnClearInput.setText(LocationManager.GPS_PROVIDER);
        gps.setProvider(LocationManager.GPS_PROVIDER);
    }
}

From source file:net.evecom.androidecssp.activity.event.EventInfoActivity.java

/**
 * /*w  w  w . j  a  va 2 s.c om*/
 *  
 * 
 * @author Mars zhang
 * @created 2015-12-1 11:45:22
 */
private void requestLocationUpdate() {
    //  
    mMyLocation = new MyOverlay(EventInfoActivity.this, null);
    // 
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        //            toast("", 0);
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, mMyLocation);
    } else if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 1, mMyLocation);
        //            toast("", 0);
    } else {
        //            toast("", 0);
    }
}

From source file:com.android.launcher3.widget.DigitalAppWidgetProvider.java

private void updateClock(Context context, AppWidgetManager appWidgetManager, int appWidgetId, float ratio) {
    RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget);

    // Launch setinngs when clicking on the time in the widget only if not a lock screen widget
    Bundle newOptions = appWidgetManager.getAppWidgetOptions(appWidgetId);
    if (newOptions != null && newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY,
            -1) != AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD) {
        Intent mIntent = new Intent(Intent.ACTION_MAIN);
        mIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        ComponentName component = new ComponentName("com.android.settings", "com.android.settings.Settings");
        mIntent.setComponent(component);
        widget.setOnClickPendingIntent(R.id.digital_appwidget,
                PendingIntent.getActivity(context, 0, mIntent, 0));
    }/*from   w ww .j a v a 2s  . c o m*/

    //cg sai.pan begin
    refreshWifiStatus(context, widget);
    refreshBtStatus(context, widget);
    refreshAirplaneStatus(context, widget,
            Settings.Global.getInt(context.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0) != 0);
    mLocationManager = (LocationManager) context.getSystemService(context.LOCATION_SERVICE);
    refreshGpsStatus(context, widget, mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER));
    //refreshDataStatus(context, widget, Settings.Global.getInt(context.getContentResolver(), Settings.Global.MOBILE_DATA, 0) != 0);
    requestLocation(context);
    //cg sai.pan end

    // SPRD for bug421127 add am/pm for widget
    WidgetUtils.setTimeFormat(widget, (int) context.getResources().getDimension(R.dimen.widget_label_font_size),
            R.id.the_clock);
    WidgetUtils.setClockSize(context, widget, ratio);

    // Set today's date format
    CharSequence dateFormat = DateFormat.getBestDateTimePattern(Locale.getDefault(),
            context.getString(R.string.abbrev_wday_month_day_no_year));
    widget.setCharSequence(R.id.date, "setFormat12Hour", dateFormat);
    widget.setCharSequence(R.id.date, "setFormat24Hour", dateFormat);

    appWidgetManager.updateAppWidget(appWidgetId, widget);
}

From source file:com.vonglasow.michael.satstat.MapSectionFragment.java

/**
 * Called by {@link MainActivity} when the status of the GPS changes. Updates GPS display.
 *///from  w  w w  .j av  a2 s. c o m
public void onGpsStatusChanged(GpsStatus status, int satsInView, int satsUsed, Iterable<GpsSatellite> sats) {
    if (satsUsed == 0) {
        Location location = providerLocations.get(LocationManager.GPS_PROVIDER);
        if (location != null)
            markLocationAsStale(location);
        applyLocationProviderStyle(this.getContext(), LocationManager.GPS_PROVIDER, LOCATION_PROVIDER_GRAY);
    }
}

From source file:com.hufeiya.SignIn.activity.QuizActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
        @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    switch (requestCode) {
    case REQUEST_CODE_FOR_POSITON:
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, this);
            locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 0, this);

        } else {/*  w  ww .j  a v a2  s .  c  om*/
            // TODO permission denied, boo! Disable the
            // functionality that depends on this permission.
        }
        break;
    case REQUEST_CAMARA_PERMISSION:
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            setStateBeforeCameraPreview();
            startCameraPreview();
        }
    }

}

From source file:carsharing.starter.automotive.iot.ibm.com.mobilestarterapp.Home.CarBrowse.java

private void getAccurateLocation2(final GoogleMap googleMap) {
    final FragmentActivity activity = getActivity();
    if (activity == null) {
        return;//w  w  w.j  a  va  2  s .  c  o m
    }
    final ConnectivityManager connectivityManager = (ConnectivityManager) activity
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();

    if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
            && (networkInfo != null && networkInfo.isConnected())) {
        if (simulatedLocation == null) {
            if (ActivityCompat.checkSelfPermission(activity.getApplicationContext(),
                    Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
                    && ActivityCompat.checkSelfPermission(activity.getApplicationContext(),
                            Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                return;
            }

            locationManager = (LocationManager) activity.getApplicationContext()
                    .getSystemService(Context.LOCATION_SERVICE);

            final List<String> providers = locationManager.getProviders(true);
            Location finalLocation = null;

            for (String provider : providers) {
                if (ActivityCompat.checkSelfPermission(activity.getApplicationContext(),
                        Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
                        && ActivityCompat.checkSelfPermission(activity.getApplicationContext(),
                                Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                    return;
                }

                final Location suggestedLocation = locationManager.getLastKnownLocation(provider);

                if (suggestedLocation == null) {
                    continue;
                }
                Log.i("Location Provider",
                        "provider=" + suggestedLocation.getProvider() + " time="
                                + new SimpleDateFormat("yyyy MMM dd HH:mm:ss")
                                        .format(suggestedLocation.getTime())
                                + " accuracy=" + suggestedLocation.getAccuracy() + " lat="
                                + suggestedLocation.getLatitude() + " lng=" + suggestedLocation.getLongitude());

                if (finalLocation == null) {
                    finalLocation = suggestedLocation;
                } else if (suggestedLocation.getTime() - finalLocation.getTime() > 1000) {
                    // drop more than 1000ms old data
                    finalLocation = suggestedLocation;
                } else if (suggestedLocation.getAccuracy() < finalLocation.getAccuracy()) {
                    // picks more acculate one
                    finalLocation = suggestedLocation;
                }
            }

            location = finalLocation;
        } else {
            location = simulatedLocation;
        }
        if (location != null) {
            final LatLng userLocation = new LatLng(location.getLatitude(), location.getLongitude());

            mMap.addMarker(new MarkerOptions().position(userLocation).title("Your Location"));

            mMap.moveCamera(CameraUpdateFactory.newLatLng(userLocation));
            mMap.animateCamera(CameraUpdateFactory.zoomTo(14), 2000, null);

            getCars(location);
        } else {
            Log.e("Location Data", "Not Working!");

            //                Toast.makeText(getActivity().getApplicationContext(), "Please activate your location settings and restart the application!", Toast.LENGTH_LONG).show();
            getAccurateLocation(mMap);
        }
    } else {
        if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
            Toast.makeText(activity.getApplicationContext(), "Please turn on your GPS", Toast.LENGTH_LONG)
                    .show();

            final Intent gpsIntent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            startActivityForResult(gpsIntent, GPS_INTENT);

            if (networkInfo == null) {
                networkIntentNeeded = true;
            }
        } else {
            if (networkInfo == null) {
                Toast.makeText(activity.getApplicationContext(), "Please turn on Mobile Data or WIFI",
                        Toast.LENGTH_LONG).show();

                final Intent settingsIntent = new Intent(Settings.ACTION_SETTINGS);
                startActivityForResult(settingsIntent, SETTINGS_INTENT);
            }
        }
    }
}

From source file:com.nextgis.maplibui.service.TrackerService.java

@Override
public void onLocationChanged(Location location) {
    boolean update = LocationUtil.isProviderEnabled(this, location.getProvider(), true);
    if (!mIsRunning || !update)
        return;//from   w  w  w.j a  v  a2s  .  c o m

    if (mHasGPSFix && !location.getProvider().equals(LocationManager.GPS_PROVIDER))
        return;

    String fixType = location.hasAltitude() ? "3d" : "2d";

    mValues.clear();
    mValues.put(TrackLayer.FIELD_SESSION, mTrackId);

    mPoint.setCoordinates(location.getLongitude(), location.getLatitude());
    mPoint.setCRS(GeoConstants.CRS_WGS84);
    mPoint.project(GeoConstants.CRS_WEB_MERCATOR);
    mValues.put(TrackLayer.FIELD_LON, mPoint.getX());
    mValues.put(TrackLayer.FIELD_LAT, mPoint.getY());
    mValues.put(TrackLayer.FIELD_ELE, location.getAltitude());
    mValues.put(TrackLayer.FIELD_FIX, fixType);
    mValues.put(TrackLayer.FIELD_SAT, mSatellitesCount);
    mValues.put(TrackLayer.FIELD_TIMESTAMP, location.getTime());
    getContentResolver().insert(mContentUriTrackPoints, mValues);

    List<ILayer> tracks = getTrackLayers();
    if (tracks.size() > 0) {
        IGISApplication app = (IGISApplication) getApplication();
        Uri uri = Uri.parse("content://" + app.getAuthority() + "/" + tracks.get(0).getPath().getName());
        mValues.remove(TrackLayer.FIELD_LAT);
        mValues.remove(TrackLayer.FIELD_LON);
        try {
            mValues.put(FIELD_GEOM, mPoint.toBlob());
        } catch (IOException e) {
            e.printStackTrace();
        }

        getContentResolver().insert(uri, mValues);
        sync(app);
    }
}

From source file:com.nextgis.forestinspector.fragment.MapFragment.java

protected void fillTextViews(Location location) {
    if (null == location) {
        setDefaultTextViews();//w w  w  . ja va2 s  .  co m
    } else {
        if (location.getProvider().equals(LocationManager.GPS_PROVIDER)) {
            int satellites = location.getExtras().getInt("satellites");
            if (satellites < GpsEventSource.MIN_SATELLITES_IN_FIX) {
                mStatusSource.setText("");
                mStatusSource.setCompoundDrawablesWithIntrinsicBounds(
                        getResources().getDrawable(R.drawable.ic_location), null, null, null);
            } else {
                mStatusSource.setText(satellites + "");
                mStatusSource.setCompoundDrawablesWithIntrinsicBounds(
                        getResources().getDrawable(R.drawable.ic_location), null, null, null);
            }
        } else {
            mStatusSource.setText("");
            mStatusSource.setCompoundDrawablesWithIntrinsicBounds(
                    getResources().getDrawable(R.drawable.ic_signal_wifi), null, null, null);
        }

        mStatusAccuracy
                .setText(String.format("%.1f %s", location.getAccuracy(), getString(R.string.unit_meter)));
        mStatusAltitude
                .setText(String.format("%.1f %s", location.getAltitude(), getString(R.string.unit_meter)));
        mStatusSpeed.setText(String.format("%.1f %s/%s", location.getSpeed() * 3600 / 1000,
                getString(R.string.unit_kilometer), getString(R.string.unit_hour)));
        mStatusLatitude.setText(LocationUtil.formatCoordinate(location.getLatitude(), mCoordinatesFormat) + " "
                + getString(R.string.latitude_caption_short));
        mStatusLongitude.setText(LocationUtil.formatCoordinate(location.getLongitude(), mCoordinatesFormat)
                + " " + getString(R.string.longitude_caption_short));
    }
}

From source file:com.detroitteatime.autocarfinder.Main.java

public static void makeSureGPSIsOn(Context c) {
    LocationManager service = (LocationManager) c.getSystemService(LOCATION_SERVICE);
    boolean enabled = service.isProviderEnabled(LocationManager.GPS_PROVIDER);

    // Check if enabled and if not send user to the GSP settings
    // Better solution would be to display a dialog and suggesting to
    // go to the settings
    if (!enabled) {
        Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        c.startActivity(intent);/*w ww.j  a v  a2s  .  c  om*/
    }

}