Example usage for android.location LocationManager PASSIVE_PROVIDER

List of usage examples for android.location LocationManager PASSIVE_PROVIDER

Introduction

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

Prototype

String PASSIVE_PROVIDER

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

Click Source Link

Document

A special location provider for receiving locations without actually initiating a location fix.

Usage

From source file:org.hansel.myAlert.LocationManagement.java

private void getLocation() {
    if (mLocationClient != null && mLocationClient.isConnected()
            && isBetterLocation(mLocationClient.getLastLocation(), mLocation)) {
        mLocation = mLocationClient.getLastLocation();
    } else {/*from w w w  .  j  a  v a2 s .  c  o m*/
        mLocation = mLocationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
    }

    if (mLocation != null) {
        //   escribe(mBestProvider+  "     http://maps.google.com/?q="+mLocation.getLatitude()+","
        //   +mLocation.getLongitude());
        Log.v("" + "     http://maps.google.com/?q=" + mLocation.getLatitude() + ","
                + mLocation.getLongitude());
    } else {
        try {
            Log.v("error tomando el GPS vamos a hacerlo por celdas ");
            String posicionCeldas = tMgr.getCellLocation().toString().replace("[", "").replace("]", "");
            System.out.println(posicionCeldas);
            //09-14 12:14:37.599: I/System.out(1980): ....> [8,2703,8,19.4311,-99.16801]
            try {
                if (!posicionCeldas.equals("")) {
                    //   Vector<String> celdas = Util.splitVector(posicionCeldas, ",");
                    //Latitud = Double.valueOf(celdas.get(3));
                    //longitud = Double.valueOf( celdas.get(4));
                    //   escribe("Celdas: http://maps.google.com/?q="+Latitud+","+longitud);

                }
            } catch (ArrayIndexOutOfBoundsException a) {
                // TODO: handle exception
                System.out.println("No se encontro tampoco por las celdas -> " + a.getMessage());
            } catch (Exception e) {
                Log.v("Error usando Celdas:" + e.getMessage());
            }
        } catch (Exception ex) {
            Log.v("Error obteniendo celdas:" + ex.getMessage());
        }
    }
}

From source file:de.grobox.liberario.ui.LocationGpsView.java

public void activateGPS() {
    if (searching)
        return;//w ww.  j av a 2  s  .  c o  m

    // check permissions
    if (ContextCompat.checkSelfPermission(getContext(),
            Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(activity,
                Manifest.permission.ACCESS_FINE_LOCATION)) {
            Toast.makeText(getContext(), R.string.permission_denied_gps, Toast.LENGTH_LONG).show();
        } else {
            // No explanation needed, we can request the permission
            ActivityCompat.requestPermissions(activity,
                    new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, caller);
        }

        return;
    }

    searching = true;

    List<String> providers = locationManager.getProviders(true);

    for (String provider : providers) {
        // Register the listener with the Location Manager to receive location updates
        locationManager.requestSingleUpdate(provider, this, null);

        Log.d(getClass().getSimpleName(), "Register provider for location updates: " + provider);
    }

    // check if there is a non-passive provider available
    if (providers.size() == 0
            || (providers.size() == 1 && providers.get(0).equals(LocationManager.PASSIVE_PROVIDER))) {
        locationManager.removeUpdates(this);
        Toast.makeText(getContext(), getContext().getString(R.string.error_no_location_provider),
                Toast.LENGTH_LONG).show();

        return;
    }

    // clear input
    setLocation(null, TransportrUtils.getTintedDrawable(getContext(), R.drawable.ic_gps));
    ui.clear.setVisibility(View.VISIBLE);

    // clear current GPS location, because we are looking to find a new one
    gps_location = null;

    // show GPS button blinking
    final Animation animation = new AlphaAnimation(1, 0);
    animation.setDuration(500);
    animation.setInterpolator(new LinearInterpolator());
    animation.setRepeatCount(Animation.INFINITE);
    animation.setRepeatMode(Animation.REVERSE);
    ui.status.startAnimation(animation);

    ui.location.setHint(R.string.stations_searching_position);
    ui.location.clearFocus();

    if (gpsListener != null)
        gpsListener.activateGPS();
}

From source file:io.github.runassudo.ptoffline.ui.LocationGpsView.java

public void activateGPS() {
    if (searching)
        return;//  w  ww .  ja v  a  2s  .co m

    // check permissions
    if (ContextCompat.checkSelfPermission(getContext(),
            Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(activity,
                Manifest.permission.ACCESS_FINE_LOCATION)) {
            Toast.makeText(getContext(), R.string.permission_denied_gps, Toast.LENGTH_LONG).show();
        } else {
            // No explanation needed, we can request the permission
            ActivityCompat.requestPermissions(activity,
                    new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, caller);
        }

        return;
    }

    searching = true;

    List<String> providers = locationManager.getProviders(true);

    for (String provider : providers) {
        // Register the listener with the Location Manager to receive location updates
        locationManager.requestSingleUpdate(provider, this, null);

        Log.d(getClass().getSimpleName(), "Register provider for location updates: " + provider);
    }

    // check if there is a non-passive provider available
    if (providers.size() == 0
            || (providers.size() == 1 && providers.get(0).equals(LocationManager.PASSIVE_PROVIDER))) {
        locationManager.removeUpdates(this);
        Toast.makeText(getContext(), getContext().getString(R.string.error_no_location_provider),
                Toast.LENGTH_LONG).show();

        // Set the flag that there is currently no active search. Otherwise the App won't
        // allow new searches even after GPS has been reenabled, because the app "hangs" in
        // a semistate where searching = true but now real search is active.
        searching = false;
        return;
    }

    // clear input
    setLocation(null, TransportrUtils.getTintedDrawable(getContext(), R.drawable.ic_gps));
    ui.clear.setVisibility(View.VISIBLE);

    // clear current GPS location, because we are looking to find a new one
    gps_location = null;

    // show GPS button blinking
    final Animation animation = new AlphaAnimation(1, 0);
    animation.setDuration(500);
    animation.setInterpolator(new LinearInterpolator());
    animation.setRepeatCount(Animation.INFINITE);
    animation.setRepeatMode(Animation.REVERSE);
    ui.status.startAnimation(animation);

    ui.location.setHint(R.string.stations_searching_position);
    ui.location.clearFocus();

    if (gpsListener != null)
        gpsListener.activateGPS();
}

From source file:de.grobox.liberario.locations.LocationGpsView.java

public void activateGPS() {
    if (searching)
        return;/*  w  w w. ja v a 2 s.  c  o m*/

    // check permissions
    if (ContextCompat.checkSelfPermission(getContext(),
            Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        // Should we show an explanation?
        /*         if(ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.ACCESS_FINE_LOCATION)) {
                    Toast.makeText(getContext(), R.string.permission_denied_gps, Toast.LENGTH_LONG).show();
                 } else {
                    // No explanation needed, we can request the permission
                    ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, caller);
                 }
        */
        return;
    }

    searching = true;

    List<String> providers = locationManager.getProviders(true);

    for (String provider : providers) {
        // Register the listener with the Location Manager to receive location updates
        locationManager.requestSingleUpdate(provider, this, null);

        Log.d(getClass().getSimpleName(), "Register provider for location updates: " + provider);
    }

    // check if there is a non-passive provider available
    if (providers.size() == 0
            || (providers.size() == 1 && providers.get(0).equals(LocationManager.PASSIVE_PROVIDER))) {
        locationManager.removeUpdates(this);
        Toast.makeText(getContext(), getContext().getString(R.string.error_no_location_provider),
                Toast.LENGTH_LONG).show();

        // Set the flag that there is currently no active search. Otherwise the App won't
        // allow new searches even after GPS has been reenabled, because the app "hangs" in
        // a semistate where searching = true but now real search is active.
        searching = false;
        return;
    }

    // clear input
    setLocation(null, TransportrUtils.getTintedDrawable(getContext(), R.drawable.ic_gps));
    ui.clear.setVisibility(View.VISIBLE);

    // clear current GPS location, because we are looking to find a new one
    gps_location = null;

    // show GPS button blinking
    final Animation animation = new AlphaAnimation(1, 0);
    animation.setDuration(500);
    animation.setInterpolator(new LinearInterpolator());
    animation.setRepeatCount(Animation.INFINITE);
    animation.setRepeatMode(Animation.REVERSE);
    ui.status.startAnimation(animation);

    ui.location.setHint(R.string.stations_searching_position);
    ui.location.clearFocus();

    if (gpsListener != null)
        gpsListener.activateGPS();
}

From source file:ru.dublgis.androidlocation.PassiveLocationProvider.java

public boolean startLocationUpdates(final int minTime) {
    try {//from  ww w  .j av a2 s  .c o  m
        if (null != mContext && null != mLocationManager && isPermissionGranted(mContext)) {
            mLocationManager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, minTime, 0, this,
                    mlocationUpdatesLooper);
            return true;
        }
    } catch (Throwable e) {
        Log.e(TAG, "Failed to start location updates", e);
    }
    return false;
}

From source file:us.dustinj.locationstore.LocationService.java

public void TurnOffGPS() {
    Log.d(this.getClass().getSimpleName(), "TurnOffGPS");
    m_locationManager.removeUpdates(this);
    m_locationManager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, 1000, (float) 0.1, this);
}

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

/***********************************************************************************************
 *
 * METHODS/*from www. j  av a2 s  .co 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:com.vonglasow.michael.satstat.PasvLocListenerService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    mSharedPreferences.registerOnSharedPreferenceChangeListener(this);

    mNotifyFix = mSharedPreferences.getBoolean(SettingsActivity.KEY_PREF_NOTIFY_FIX, false);
    mNotifySearch = mSharedPreferences.getBoolean(SettingsActivity.KEY_PREF_NOTIFY_SEARCH, false);

    if (mLocationManager.getAllProviders().indexOf(LocationManager.PASSIVE_PROVIDER) >= 0) {
        mLocationManager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, 0, 0, this);
    } else {/*from  w  ww  . ja va2 s .com*/
        Log.w("PasvLocListenerService",
                "No passive location provider found. Data display will not be available.");
    }

    mLocationManager.addGpsStatusListener(this);

    mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_stat_notify_location)
            .setContentTitle(getString(R.string.value_none)).setContentText(getString(R.string.value_none))
            .setWhen(0);

    Intent mainIntent = new Intent(this, MainActivity.class);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(mainIntent);

    PendingIntent mainPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    mBuilder.setContentIntent(mainPendingIntent);

    // if we were started through a broadcast, mGpsStatusReceiver had
    // no way of picking it up, so we need to forward it manually
    mGpsStatusReceiver.onReceive(this, intent);

    return START_STICKY;
}

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

private void getloc() {
    if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        loc_string = "none";// indicate that no gps data
        return;/*from w ww.j a  v  a  2s.  c o m*/
    }
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setBearingRequired(true);
    criteria.setCostAllowed(true);
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    criteria.setAltitudeRequired(false);
    String bestProvider = locationManager.getBestProvider(criteria, true);
    if (ActivityCompat.checkSelfPermission(this,
            android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(this,
                    android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        return;
    }
    locationManager.requestLocationUpdates(bestProvider, 2000, 10, new LocationListener() {
        @Override
        public void onStatusChanged(String s, int i, Bundle bundle) {
        }

        @Override
        public void onProviderEnabled(String s) {
        }

        @Override
        public void onProviderDisabled(String s) {
        }

        @Override
        public void onLocationChanged(final Location location) {
        }
    });
    Location myLocation = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
    double longitude = myLocation.getLongitude();
    double latitude = myLocation.getLatitude();
    loc_string = latitude + "-" + longitude;

}

From source file:planets.position.Planets.java

/**
 * Gets the GPS location of the device or loads test values.
 *//*from   w w w .j av a 2 s . co  m*/
public void getLocation() {
    // Remove the location alert dialog if it is visible.
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    Fragment prev = getSupportFragmentManager().findFragmentByTag("locDialogMain");
    if (prev != null) {
        ft.remove(prev);
    }
    ft.commit();
    // get lat/long from GPS
    if (DEBUG) {
        // Test data to use with the emulator
        latitude = 32.221743;
        longitude = -110.926479;
        elevation = 713.0;
        date = Calendar.getInstance().getTimeInMillis();
        offset = -7.0;
        saveLocation();
    } else {
        loc = null;
        gpsTask = new GetGPSTask();
        gpsTask.execute();
        boolean result = userLocation.getLocation(this, locationResult);
        if (!result) {
            loc = new Location(LocationManager.PASSIVE_PROVIDER);
        }
    }
}