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.mobicage.rogerthat.GetLocationActivity.java

private void getMyLocation() {
    mLocationProviderUpdates = mUseGPS.isChecked() ? LocationManager.GPS_PROVIDER
            : LocationManager.NETWORK_PROVIDER;
    mLocation = null;//from w  w  w.java  2 s .  co  m
    try {
        mLocationManager.requestLocationUpdates(mLocationProviderUpdates, 0, 0, mLocationListener);
    } catch (SecurityException e) {
        L.bug(e); // Should never happen
    }
    mLocationQueryStart = System.currentTimeMillis();
    mProgressDialog.setProgress(0);
    mProgressDialog.show();
    mService.postDelayedOnUIHandler(mUpdateProgress, 100);
}

From source file:es.rgmf.libresportgps.MainActivity.java

/**
 * Check if GPS is enabled. If GPS is not enabled then It shows an Dialog
 * through the user can enabled it./*  w w w  . j av  a  2  s. c  o m*/
 */
private void checkGpsProvider() {
    LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE);
    if (!lm.isProviderEnabled(LocationManager.GPS_PROVIDER) && !Session.isAlertDialogGPSShowed()) {
        Session.setAlertDialogGPSShowed(true);
        new AlertDialog.Builder(this).setTitle(R.string.gps_disabled)
                .setIcon(android.R.drawable.ic_dialog_alert)
                .setMessage(getResources().getString(R.string.gps_disabled_hint)).setCancelable(true)
                .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                    }
                }).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                }).create().show();
    }
}

From source file:com.tonyandr.caminoguideoff.map.MapActivity.java

private void checkGPS() {
    LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE);
    if (!lm.isProviderEnabled(LocationManager.GPS_PROVIDER)
            && !lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
        // Build the alert dialog
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Where are you?");
        builder.setMessage("Please enable Location Services and GPS");
        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            @Override/*from  w  w w .  ja v  a  2  s  .c o  m*/
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });
        builder.setPositiveButton("Enable", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialogInterface, int i) {
                // Show location settings when the user acknowledges the alert dialog
                Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                startActivity(intent);
            }
        });
        Dialog alertDialog = builder.create();
        alertDialog.setCanceledOnTouchOutside(false);
        alertDialog.show();
    }
}

From source file:gov.nasa.arc.geocam.geocam.GeoCamMobile.java

@Override
public void onResume() {
    super.onResume();
    Log.d(DEBUG_ID, "GeoCamMobile::onResume called");

    mForeground.foreground();//from w w w  .j  a va2  s  .  c om

    mServiceBound = bindService(new Intent(this, GeoCamService.class), mServiceConn, Context.BIND_AUTO_CREATE);
    if (!mServiceBound) {
        Log.e(DEBUG_ID, "GeoCamMobile::onResume - error binding to service");
    }

    IntentFilter filter = new IntentFilter(GeoCamMobile.LOCATION_CHANGED);
    this.registerReceiver(mLocationReceiver, filter);

    LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        showDialog(DIALOG_GPS_OFF_ID);
    }
}

From source file:com.esri.cordova.geolocation.AdvancedGeolocation.java

private void validatePermissions() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        // Reference: Permission Groups https://developer.android.com/guide/topics/security/permissions.html#normal-dangerous
        // As of July 2016 - ACCESS_WIFI_STATE and ACCESS_NETWORK_STATE are not considered dangerous permissions
        Log.d(TAG, "validatePermissions()");

        final int showRationale = _permissionsController.getShowRationale();

        if (_permissionsController.getAppPermissions()) {
            startLocation();/*from   w  w  w.  ja v  a2s . c o  m*/
        }
        // The user has said to never ask again about activating location services
        else if (showRationale == _permissionsController.DENIED_NOASK) {
            Log.w(TAG, ErrorMessages.LOCATION_SERVICES_DENIED_NOASK().message);
            sendCallback(PluginResult.Status.ERROR,
                    JSONHelper.errorJSON(PROVIDER_PRIMARY, ErrorMessages.LOCATION_SERVICES_DENIED_NOASK()));
        } else if (showRationale == _permissionsController.ALLOW) {
            requestPermissions();
        } else if (showRationale == _permissionsController.DENIED) {
            Log.w(TAG, "Rationale already shown, geolocation denied twice");
            sendCallback(PluginResult.Status.ERROR,
                    JSONHelper.errorJSON(PROVIDER_PRIMARY, ErrorMessages.LOCATION_SERVICES_DENIED()));
        }
    } else {
        final LocationManager _locationManager = (LocationManager) _cordovaActivity
                .getSystemService(Context.LOCATION_SERVICE);
        final boolean networkLocationEnabled = _locationManager
                .isProviderEnabled(LocationManager.NETWORK_PROVIDER);
        final boolean gpsEnabled = _locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
        final boolean networkEnabled = isInternetConnected(_cordovaActivity.getApplicationContext());

        // If warnings are disabled then skip initializing alert dialog fragments
        if (!_noWarn && (!networkLocationEnabled || !gpsEnabled || !networkEnabled)) {
            alertDialog(gpsEnabled, networkLocationEnabled, networkEnabled);
        } else {
            startLocation();
        }
    }
}

From source file:au.gov.ga.worldwind.androidremote.client.Remote.java

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

    //Normally one shouldn't instantiate all these objects in the onCreate method,
    //as onCreate is called every time a configuration change occurs (orientation,
    //keyboard hidden, screen size, etc). But we are handling configuration changes
    //ourselves./*from   w  ww . j  ava2 s  .  co m*/

    //hide the status bar
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    //get local Bluetooth adapter
    bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (bluetoothAdapter == null) {
        Toast.makeText(this, R.string.bluetooth_unavailable, Toast.LENGTH_LONG).show();
        finish();
        return;
    }

    communicator = new AndroidCommunicator(this, bluetoothAdapter);
    communicator.addListener(this);

    remoteViewCommunicator = new SocketAndroidCommunicator(this);

    DatasetModelState datasetsState = new DatasetModelState(communicator, this);
    LayerModelState layersState = new LayerModelState(communicator, this);
    PlaceModelState placesState = new PlaceModelState(communicator, this);

    ItemModelState[] states = new ItemModelState[] { datasetsState, layersState, placesState };
    for (ItemModelState state : states) {
        itemModelStates.put(state.getModel().getId(), state);
        ItemModelFragmentMenuProvider menuProvider = new EmptyMenuProvider();
        if (state == placesState) {
            menuProvider = new PlacesMenuProvider(communicator);
        }
        menuProviders.put(state.getModel().getId(), menuProvider);
    }

    controlFragment = ControlFragment.newInstance(remoteViewCommunicator);
    datasetsFragment = ItemModelFragment.newInstance(datasetsState.getModel().getId(), false);
    layersFragment = ItemModelFragment.newInstance(layersState.getModel().getId(), false);
    flatLayersFragment = ItemModelFragment.newInstance(layersState.getModel().getId(), true);
    placesFragment = ItemModelFragment.newInstance(placesState.getModel().getId(), false);
    tabFragments = new Fragment[] { controlFragment, datasetsFragment, layersFragment, flatLayersFragment,
            placesFragment };

    //create the tabs
    getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    int[] tabIds = new int[] { R.string.controls_tab, R.string.datasets_tab, R.string.layers_tab,
            R.string.flat_layers_tab, R.string.places_tab };
    for (int i = 0; i < tabIds.length; i++) {
        ActionBar.Tab tab = getSupportActionBar().newTab();
        tab.setTag(tabIds[i]);
        tab.setText(tabIds[i]);
        tab.setTabListener(this);
        getSupportActionBar().addTab(tab);
    }

    getSupportActionBar().setDisplayShowTitleEnabled(false);
    getSupportActionBar().setHomeButtonEnabled(true);

    //setup the shake sensor
    sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    sensorListener.setOnShakeListener(new ShakeEventListener.OnShakeListener() {
        @Override
        public void onShake() {
            communicator.sendMessage(new ShakeMessage());
        }
    });

    // Acquire a reference to the system Location Manager
    LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    // Define a listener that responds to location updates
    LocationListener locationListener = new LocationListener() {
        public void onLocationChanged(Location location) {
            if (isSendLocation()) {
                communicator.sendMessage(new LocationMessage(location.getLatitude(), location.getLongitude(),
                        location.getAltitude(), location.getAccuracy(), location.getBearing()));
            }
        }

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

        public void onProviderEnabled(String provider) {
        }

        public void onProviderDisabled(String provider) {
        }
    };
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
    //locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
}

From source file:au.org.ala.fielddata.mobile.MobileFieldDataDashboard.java

@Override
public void onStart() {
    super.onStart();
    if (isLoggedIn()) {
        if (!preferences.getAskedAboutWifi()) {
            showWifiPreferenceDialog();//from   w  w w  .  j  a  v  a  2s  .c  o  m
        }

        if (!askedAboutGPS) {
            if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS)) {
                LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
                if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
                    showNoGpsDialog();
                }
            }
        }
    }
}

From source file:com.mobantica.DriverItRide.activities.ActivityLogin.java

private boolean valid() {
    if (edt_login_username.getText().toString().equals("")) {
        Toast.makeText(getApplicationContext(), getResources().getString(R.string.please_enter_username),
                Toast.LENGTH_SHORT).show();
        return false;
    }//from   w  ww  . j av  a2s. c o m

    if (edt_login_password.getText().toString().equals("")) {
        Toast.makeText(getApplicationContext(), getResources().getString(R.string.please_enter_password),
                Toast.LENGTH_SHORT).show();
        return false;
    }

    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        Toast.makeText(this, getResources().getString(R.string.need_location_permission_in_app_setting),
                Toast.LENGTH_SHORT).show();
        return false;
    }

    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
        Toast.makeText(this, getResources().getString(R.string.need_phone_permission_in_app_setting),
                Toast.LENGTH_SHORT).show();
        return false;
    }

    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        Toast.makeText(this,
                getResources().getString(R.string.need_write_external_storage_permissionin_app_setting),
                Toast.LENGTH_SHORT).show();
        return false;
    }

    LocationManager locationManager = (LocationManager) getApplicationContext()
            .getSystemService(Context.LOCATION_SERVICE);
    if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
            && !locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
        Toast.makeText(getApplicationContext(), getResources().getString(R.string.please_enable_location),
                Toast.LENGTH_SHORT).show();
        return false;
    }

    return true;
}

From source file:com.alexandreroman.nrelay.NmeaRelayService.java

public void startNmeaRelay() throws IOException {
    if (relaying) {
        Log.d(TAG, "Already relaying: do nothing");
        return;// ww  w  .ja  v  a2 s  .co m
    }

    context.reset();

    pLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
    pLock.acquire();
    updateState(State.STARTING);

    nmeaWorker = new NmeaRelayWorker();
    nmeaWorker.start();

    Log.d(TAG, "Requesting location updates through GPS");
    locationManager.addNmeaListener(this);
    locationManager.addGpsStatusListener(this);
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 4000, 0, this);

    Log.i(TAG, "NMEA relay started");
    relaying = true;
    fireNmeaRelayContextChanged();
}

From source file:com.android.gpstest.GpsTestActivity.java

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

    if (GpsTestUtil.isRotationVectorSensorSupported(this)) {
        // Use the modern rotation vector sensors
        Sensor vectorSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR);
        mSensorManager.registerListener(this, vectorSensor, 16000); // ~60hz
    } else {//  w w w  .  j  a  v a 2 s  .co  m
        // Use the legacy orientation sensors
        Sensor sensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
        if (sensor != null) {
            mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_GAME);
        }
    }

    if (!mService.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        promptEnableGps();
    }

    /**
     * Check preferences to see how they should be initialized
     */
    SharedPreferences settings = Application.getPrefs();

    checkKeepScreenOn(settings);

    checkTimeAndDistance(settings);

    checkTutorial(settings);

    checkTrueNorth(settings);
}