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:com.poguico.palmabici.synchronizers.LocationSynchronizer.java

public LocationSynchronizer(FragmentActivity context) {
    manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    listener = new LocationListener() {

        @Override//w  w  w .j  a v  a2s.c o  m
        public void onLocationChanged(Location l) {
            location = l;
            updateViews();
        }

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
        }

        @Override
        public void onProviderEnabled(String provider) {
        }

        @Override
        public void onProviderDisabled(String provider) {
            if ((provider.equals(LocationManager.GPS_PROVIDER)
                    && !manager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
                    || (provider.equals(LocationManager.NETWORK_PROVIDER)
                            && !manager.isProviderEnabled(LocationManager.GPS_PROVIDER))) {
                location = null;
                updateViews();
            }
        }
    };

    manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000L, 0, listener);
    manager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 10000L, 0, listener);

    if (location == null)
        location = manager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

    if (location == null)
        location = manager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

    synchronizableElements = new ArrayList<SynchronizableElement>();
}

From source file:edu.cmu.sv.trailscribe.view.BaseActivity.java

protected void setLocation(LocationListener locationListener) {
    mLocationManager = mApplication.getLocationManager();

    // Register only GPS as provider
    // Keep minTime as 60 seconds and 10 meters as minDistance
    mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
            TrailScribeApplication.MIN_REQUEST_TIME, TrailScribeApplication.MIN_REQUEST_DISTANCE, this);
    // Do not register Network as location provider - Yields unreliable coordinate information
    // mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, TrailScribeApplication.MIN_REQUEST_TIME, TrailScribeApplication.MIN_REQUEST_DISTANCE, this);        

    mLocation = mApplication.getLocation();
}

From source file:com.nextgis.maplibui.util.NotificationHelper.java

public static void showLocationInfo(final Context context) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    if (!preferences.getBoolean(SettingsConstantsUI.KEY_PREF_SHOW_GEO_DIALOG, true))
        return;//  w  w  w  .j  a va2s. c om

    LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    final boolean isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
    final boolean isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);

    if (!isGPSEnabled || !isNetworkEnabled) {
        String title, info;

        if (!isGPSEnabled && !isNetworkEnabled) {
            title = context.getString(R.string.location_disabled);
            info = context.getString(R.string.location_disabled_msg);
        } else {
            String network = "", gps = "";

            if (!isNetworkEnabled)
                network = "\r\n- " + context.getString(R.string.location_network);

            if (!isGPSEnabled)
                gps = "\r\n- " + context.getString(R.string.location_gps);

            title = context.getString(R.string.location_accuracy);
            info = context.getString(R.string.location_inaccuracy) + network + gps;
        }

        if (context instanceof Activity)
            showLocationDialog(context, title, info);
        else
            showLocationNotification(context, title, info);
    }
}

From source file:com.sanbo.synchronizers.LocationSynchronizer.java

public LocationSynchronizer(FragmentActivity context) {
    manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    listener = new LocationListener() {

        @Override/*from www.j a va  2 s . c o m*/
        public void onLocationChanged(Location l) {
            location = l;
            updateViews();
        }

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
        }

        @Override
        public void onProviderEnabled(String provider) {
        }

        @Override
        public void onProviderDisabled(String provider) {
            if ((provider.equals(LocationManager.GPS_PROVIDER)
                    && !manager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
                    || (provider.equals(LocationManager.NETWORK_PROVIDER)
                            && !manager.isProviderEnabled(LocationManager.GPS_PROVIDER))) {
                location = null;
                updateViews();
            }
        }
    };

    manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000L, 0, listener);
    manager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 10000L, 0, listener);

    if (location == null)
        location = manager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

    if (location == null)
        location = manager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

    synchronizableElements = new ArrayList<SynchronizableActivity>();
}

From source file:com.commonsware.android.strict.WeatherDemo.java

@Override
public void onResume() {
    super.onResume();

    mgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3600000, 1000, onLocationChange);
}

From source file:com.orange.datavenue.LocationService.java

public void start() {
    Log.d(TAG_NAME, "start()");
    mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    mGpsListener = new MyLocationListener();
    mNetworkListener = new MyLocationListener();

    mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 10, mGpsListener);
    mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5000, 10, mNetworkListener);
}

From source file:com.prey.services.LocationService.java

@Override
public void onCreate() {
    PreyLogger.d("LocationService is going to be started...");

    androidLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || (ActivityCompat.checkSelfPermission(this,
            Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
            || ActivityCompat.checkSelfPermission(this,
                    Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED)) {

        LocationProvider gpsLocationProvider = androidLocationManager.getProvider(LocationManager.GPS_PROVIDER);
        LocationProvider networkProvider = androidLocationManager.getProvider(LocationManager.NETWORK_PROVIDER);
        if (gpsLocationProvider != null
                && androidLocationManager.isProviderEnabled(gpsLocationProvider.getName())) {
            androidLocationManager.requestLocationUpdates(gpsLocationProvider.getName(),
                    PreyConfig.UPDATE_INTERVAL, PreyConfig.LOCATION_PROVIDERS_MIN_REFRESH_DISTANCE,
                    gpsLocationListener);
            PreyLogger.d("GPS Location provider has been started.");
        }//from   w ww  .  j a v a 2 s  . c  o m
        if (networkProvider != null && androidLocationManager.isProviderEnabled(networkProvider.getName())) {
            androidLocationManager.requestLocationUpdates(networkProvider.getName(),
                    PreyConfig.UPDATE_INTERVAL / 4, PreyConfig.LOCATION_PROVIDERS_MIN_REFRESH_DISTANCE,
                    networkLocationListener);
            PreyLogger.d("NETWORK Location provider has been started.");
        }
    } else {
        PreyLogger.i("___________ask for permission LocationService ACCESS_FINE_LOCATION");
    }

    PreyLogger.d("LocationService has been started...");
}

From source file:com.example.mohamed.a3qaqer.RegisterActvity.java

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.register_view);
    signup = (Button) findViewById(R.id.sign_up_register);
    name = (EditText) findViewById(R.id.name_edit_text);
    password = (EditText) findViewById(R.id.password_edit);
    phone = (EditText) findViewById(R.id.phone_edit_text);
    license = (EditText) findViewById(R.id.lisence_edit_text);
    address = (EditText) findViewById(R.id.address_edit_text);
    mFirebaseAuth = FirebaseAuth.getInstance();
    mProgressDialog = new ProgressDialog(this);
    mProgressDialog.setMessage("  ......");
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        buildAlertMessageNoGps();// w ww. j  a v a  2 s  .co  m
    }
    mDatabaseReference = FirebaseDatabase.getInstance().getReference().child("pharmacies");
    signUp();
}

From source file:de.tu_darmstadt.kom.freifunkfinder.user_interface.MobileLocationManager.java

/**
 * Check and register location providers
 * Reference http://stackoverflow.com/questions/2227292
 *///from   w w  w  .  ja  v a 2s.com
public void initLocation() {

    //get both provider status
    try {
        gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    try {
        networkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    //open settings in case location is not enabled
    if (!gpsEnabled && !networkEnabled && !onceCalled) {
        onceCalled = true;
        buildAlertMessageNoGpsNet();
    }

    if (Build.VERSION.SDK_INT >= 23 && ContextCompat.checkSelfPermission(applicationContext,
            android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        return;
    }

    //start GPS updates
    if (gpsEnabled) {
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 50, 0, locationListenerForGps);
    }

    //start Network updates
    if (networkEnabled) {
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 50, 0,
                locationListenerForNetwork);
    }
}

From source file:me.ziccard.secureit.async.upload.PeriodicPositionUploaderTask.java

/**
 * Constructor/*from   w  w w. ja  v  a2 s. c  o m*/
 * @param context
 * @param lat
 * @param lng
 */
public PeriodicPositionUploaderTask(Context context) {
    this.context = context;
    locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);

    if (locationManager.getAllProviders().contains(LocationManager.NETWORK_PROVIDER))
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
    if (locationManager.getAllProviders().contains(LocationManager.GPS_PROVIDER))
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);

    prefs = new SecureItPreferences(context);

    this.phoneId = prefs.getPhoneId();
    this.accessToken = prefs.getAccessToken();
}