Example usage for android.location Criteria Criteria

List of usage examples for android.location Criteria Criteria

Introduction

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

Prototype

public Criteria() 

Source Link

Document

Constructs a new Criteria object.

Usage

From source file:obdii.starter.automotive.iot.ibm.com.iot4a_obdii.Home.java

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] results) {
    switch (requestCode) {
    case INITIAL_PERMISSIONS:
        if (results[0] == PackageManager.PERMISSION_GRANTED) {
            permissionsGranted();/*from  w w  w  .j av  a2  s  .co m*/
        } else {
            Toast.makeText(getApplicationContext(), "Permissions Denied", Toast.LENGTH_SHORT).show();
        }
        break;
    case INITIAL_LOCATION_PERMISSIONS:
        if (results[0] == PackageManager.PERMISSION_GRANTED) {
            if (provider == null)
                provider = locationManager.getBestProvider(new Criteria(), false);
            setChangeNetworkEnabled(false);
            checkDeviceRegistry(true);
            setChangeFrequencyEnabled(true);
        } else {
            Toast.makeText(getApplicationContext(), "Permissions Denied", Toast.LENGTH_SHORT).show();
        }
        break;
    default:
        super.onRequestPermissionsResult(requestCode, permissions, results);
    }
}

From source file:com.zainsoft.ramzantimetable.QiblaActivity.java

private void registerForGPS() {
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_COARSE);
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    criteria.setAltitudeRequired(false);
    criteria.setBearingRequired(false);//from w  ww  .  ja  v a 2s.co  m
    criteria.setSpeedRequired(false);
    criteria.setCostAllowed(true);
    LocationManager locationManager = ((LocationManager) getSystemService(Context.LOCATION_SERVICE));
    String provider = locationManager.getBestProvider(criteria, true);

    if (provider != null) {
        locationManager.requestLocationUpdates(provider, MIN_LOCATION_TIME, MIN_LOCATION_DISTANCE,
                qiblaManager);
    }
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_LOCATION_TIME,
            MIN_LOCATION_DISTANCE, qiblaManager);
    locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MIN_LOCATION_TIME,
            MIN_LOCATION_DISTANCE, qiblaManager);
    Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    if (location == null) {
        location = ((LocationManager) getSystemService(Context.LOCATION_SERVICE))
                .getLastKnownLocation(LocationManager.GPS_PROVIDER);
    }
    if (location != null) {
        qiblaManager.onLocationChanged(location);
    }

}

From source file:reportsas.com.formulapp.Formulario.java

public void CapturaL() {
    if (parametroGPS == null) {

        parametroGPS = new ParametrosRespuesta(1);
        manejador = (LocationManager) getSystemService(LOCATION_SERVICE);
        Criteria criterio = new Criteria();
        criterio.setCostAllowed(false);// w w  w.j  ava  2  s.  c  o m
        criterio.setAltitudeRequired(false);
        criterio.setAccuracy(Criteria.ACCURACY_FINE);
        proveedor = manejador.getBestProvider(criterio, true);
        Location localizacion = manejador.getLastKnownLocation(proveedor);
        capturarLocalizacion(localizacion);

    }

    Intent intentoDlgUno = new Intent(this, dialogUbicacion.class);
    intentoDlgUno.putExtra("location", parametroGPS.getValor());
    startActivityForResult(intentoDlgUno, 0);

}

From source file:org.cesar.geofencesdemo.ui.activities.MainActivity.java

private void setUpMapIfNeeded() {

    // Do a null check to confirm that we have not already instantiated the
    // map.//from  ww  w .  j  ava2 s  .  c o  m
    if (mGoogleMap == null) {
        mGoogleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
        // Check if we were successful in obtaining the map.
        if (mGoogleMap != null) {
            // The Map is verified. It is now safe to manipulate the map.
            mGoogleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
            mGoogleMap.setMyLocationEnabled(true);
            mGoogleMap.setOnCameraChangeListener(this);

            LatLng latLng = null;
            // If we have a previous location set, we go there
            if (mSimplegeofence != null) {
                latLng = new LatLng(mSimplegeofence.getLatitude(), mSimplegeofence.getLongitude());
            } else {
                // If we don't have a previous location set, we try to go to
                // the last known position, if it's
                // not possible, then we go to the 0.0, 0.0 location
                LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
                String bestProvider = locationManager.getBestProvider(new Criteria(), true);
                Location location = locationManager.getLastKnownLocation(bestProvider);
                if (location != null) {
                    latLng = new LatLng(location.getLatitude(), location.getLongitude());
                } else {
                    latLng = new LatLng(0, 0);
                }
            }
            updateCamera(latLng);
        }
    }
}

From source file:ca.nehil.rter.streamingapp2.StreamingActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Orientation listenever implementation
    myOrientationEventListener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL) {
        @Override/*  w w  w . jav  a2 s.  com*/
        public void onOrientationChanged(int orientation) {
            int rotation = getWindowManager().getDefaultDisplay().getRotation();
            if (rotation == Surface.ROTATION_270) {
                flipVideo = true;
            } else {
                flipVideo = false;
            }
        }
    };
    myOrientationEventListener.enable();

    // stopService(new Intent(StreamingActivity.this,
    // BackgroundService.class));

    Log.e(TAG, "onCreate");

    AndroidId = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID);
    frameInfo = new FrameInfo();
    // openGL overlay
    overlay = new OverlayController(this);
    // orientation
    mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
    mAcc = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    mMag = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);

    //setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    setContentView(R.layout.activity_streaming);

    // Find the total number of cameras available
    numberOfCameras = Camera.getNumberOfCameras();

    cookies = getSharedPreferences("RterUserCreds", MODE_PRIVATE);
    prefEditor = cookies.edit();
    setUsername = cookies.getString("Username", "not-set");
    setRterCredentials = cookies.getString("RterCreds", "not-set");
    if (setRterCredentials.equalsIgnoreCase("not-set") || setRterCredentials == null) {
        Log.e("PREFS", "Login Not successful, please restart");
    }
    Log.d("PREFS", "Prefs ==> rter_Creds:" + setRterCredentials);

    // Get the location manager
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    // Define the criteria how to select the location provider -> use
    // default

    if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        Log.e(TAG, "GPS not available");
    }
    Criteria criteria = new Criteria();
    provider = locationManager.getBestProvider(criteria, true);
    Log.d(TAG, "Requesting location");
    locationManager.requestLocationUpdates(provider, 0, 1, this);
    // register the overlay control for location updates as well, so we get
    // the geomagnetic field
    locationManager.requestLocationUpdates(provider, 0, 1000, overlay);
    if (provider != null) {
        Location location = locationManager.getLastKnownLocation(provider);
        // Initialize the location fields
        if (location != null) {
            System.out.println("Provider " + provider + " has been selected. and location " + location);
            onLocationChanged(location);
        } else {
            Toast toast = Toast.makeText(this, "Location not available", Toast.LENGTH_LONG);
            toast.setGravity(Gravity.TOP, 0, 0);
            toast.show();
            lati = (float) (45.505958f);
            longi = (float) (-73.576254f);
            Log.d(TAG, "Location not available");
        }
    }

    // power manager
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, CLASS_LABEL);
    mWakeLock.acquire();

    // test, set desired orienation to north
    overlay.letFreeRoam(false);
    overlay.setDesiredOrientation(0.0f);
    // CharSequence text = "Tap to start..";
    // int duration = Toast.LENGTH_SHORT;
    //
    // Toast toast = Toast.makeText(this, text, duration);
    // toast.setGravity(Gravity.TOP|Gravity.RIGHT, 0, 0);
    // toast.show();

}

From source file:com.kmshack.BusanBus.activity.SearchMainActivity.java

private void loadLocation() {

    if (mGoogleMap == null)
        return;// w w w.j  a  v  a  2 s.co  m

    GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
    Criteria criteria = new Criteria();
    String provider = mLocationManager.getBestProvider(criteria, true);

    if (provider == null) { //       
        DialogInterface.OnClickListener cancel = new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                Location gpsLocation = mLocationManager.getLastKnownLocation("gps");

                if (gpsLocation != null) {
                    onLocationChanged(gpsLocation);
                }
            }
        };
        DialogInterface.OnClickListener ok = new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                startActivityForResult(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS),
                        0);
            }
        };

        new AlertDialog.Builder(this).setTitle(" ").setMessage(
                "       .   ?")
                .setPositiveButton("", ok).setNegativeButton("", cancel).show();

    } else { //       .
        mLocationManager.requestLocationUpdates(provider, 1, 1, this);
        mGoogleMap.setMyLocationEnabled(true);
        mGoogleMap.getMyLocation();
    }
}

From source file:com.anton.gavel.GavelMain.java

@TargetApi(Build.VERSION_CODES.GINGERBREAD)
@Override// w w  w.j  a va  2s  .  c  o  m
public void onClick(View arg0) {
    //click listener for location button

    LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setPowerRequirement(Criteria.POWER_HIGH);
    //String provider = locationManager.getBestProvider(criteria, true);

    locationManager.requestSingleUpdate(criteria, new LocationListener() {
        @Override
        public void onLocationChanged(Location location) {
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD)
                createDialog(DIALOG_NO_GEOCODING);
            else if (Geocoder.isPresent())
                (new ReverseGeocodingTask(getBaseContext())).execute(new Location[] { location });
            // Invoking reverse geocoding in an AsyncTask. 
        }

        @Override
        public void onProviderDisabled(String provider) {
        }

        @Override
        public void onProviderEnabled(String provider) {
        }

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

    }, null);

}

From source file:org.mozilla.gecko.GeckoAppShell.java

public static void enableLocation(final boolean enable) {
    getMainHandler().post(new Runnable() {
        public void run() {
            LayerView v = GeckoApp.mAppContext.getLayerController().getView();

            LocationManager lm = (LocationManager) GeckoApp.mAppContext
                    .getSystemService(Context.LOCATION_SERVICE);

            if (enable) {
                Criteria criteria = new Criteria();
                String provider = lm.getBestProvider(criteria, true);
                if (provider == null)
                    return;

                Looper l = Looper.getMainLooper();
                Location loc = lm.getLastKnownLocation(provider);
                if (loc != null) {
                    GeckoApp.mAppContext.onLocationChanged(loc);
                }//from w ww.j a v  a2s  .  c  o m
                lm.requestLocationUpdates(provider, 100, (float) .5, GeckoApp.mAppContext, l);
            } else {
                lm.removeUpdates(GeckoApp.mAppContext);
            }
        }
    });
}

From source file:com.TakeTaxi.jy.MainMapScreen.java

public void getLocalPosition() {

    lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    Criteria crit = new Criteria();
    towers = lm.getBestProvider(crit, false);
    Location location = lm.getLastKnownLocation(towers);

    if (location != null) {

        // changed lat/longi to temp for device testing
        tempLat = (int) (location.getLatitude() * 1E6);
        tempLongi = (int) (location.getLongitude() * 1E6);

    } else {//from  w w  w.  j ava 2s .  com
        // ///////////////////////////////////////////////////////////////////////////////////
        // SHOULD PUT A NO NETWORK/GPS LOC ALERT
        // /////////////////////////////////////////////////////////////////////////////////
        // /////////////////////////////////////////////////////////////////////////////////
        // /////////////////////////////////////////////////////////////////////////////////
        // /////////////////////////////////////////////////////////////////////////////////
        // /////////////////////////////////////////////////////////////////////////////////

    }
}

From source file:net.jongrakko.zipsuri.activity.PostUploadActivity.java

@Override
public void onCheckedChanged(final CompoundButton buttonView, boolean isChecked) {
    if (isChecked) {
        switch (buttonView.getId()) {
        case R.id.radioButtonAddressGPS:
            mEditTextAddress.setOnClickListener(null);
            this.mGoogleMap.setOnMapClickListener(this);
            this.mGoogleMap.setOnMyLocationButtonClickListener(this);

            if (ContextCompat.checkSelfPermission(getContext(),
                    Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
                mGoogleMap.setMyLocationEnabled(true);
                LocationProvider lprovider;
                LocationManager lm = (LocationManager) getActivity()
                        .getSystemService(getActivity().LOCATION_SERVICE);
                lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
                lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
                String provider;//  ww  w.j a v  a2s  . c o m
                Criteria criteria = new Criteria();
                criteria.setAccuracy(Criteria.ACCURACY_FINE);
                criteria.setPowerRequirement(Criteria.POWER_HIGH);
                provider = lm.getBestProvider(criteria, true);

                if (provider == null || provider.equals("passive")) { // ? ?    ??
                    new AlertDialog.Builder(getActivity()).setTitle(" ??")
                            .setNeutralButton("??", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {

                                    buttonView.toggle();
                                    startActivityForResult(
                                            new Intent(
                                                    android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS),
                                            0);
                                }
                            }).setOnCancelListener(new DialogInterface.OnCancelListener() {
                                @Override
                                public void onCancel(DialogInterface dialog) {
                                    dialog.dismiss();
                                }
                            }).show();
                } else { //  ? ?   
                    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1, 1, this);
                    Location l = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
                    if (l != null) {
                        Log.e("hello??", "okok");
                    }
                }

                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                    requestPermissions(new String[] { Manifest.permission.ACCESS_FINE_LOCATION },
                            MY_LOCATION_REQUEST_CODE);
                }
            }
            break;
        case R.id.radioButtonAddressSelf:
            this.mGoogleMap.setOnMapClickListener(null);
            mEditTextAddress.setOnClickListener(this);
            this.mGoogleMap.setOnMyLocationButtonClickListener(null);
            mGoogleMap.setMyLocationEnabled(false);
            mEditTextAddress.setOnClickListener(this);
            startActivityForResult(new Intent(getContext(), SearchAddressActivity.class), SEARCH_ADDRESS);
            break;
        }
    }
}