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:net.evecom.androidecssp.activity.WelcomeActivity.java

/**
 * gps/*from   w w w.j  a  v  a2  s  .c  om*/
 */
private void askForOpenGPS() {
    boolean gpsEnabled = Settings.Secure.isLocationProviderEnabled(getContentResolver(),
            LocationManager.GPS_PROVIDER);
    if (!gpsEnabled) {
        isNeedGpsSet = true;
        toast(",GPS,!", 1);
        Intent intent = new Intent(Settings.ACTION_SETTINGS);
        startActivityForResult(intent, 0);
    }
}

From source file:com.vonglasow.michael.satstat.ui.SettingsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_settings);

    // Show the Up button in the action bar.
    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

    // Display the fragment as the main content.
    getFragmentManager().beginTransaction().replace(android.R.id.content, new SettingsFragment()).commit();

    mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    // some logic to use the pre-1.7 setting KEY_PREF_UPDATE_WIFI as a
    // fallback if KEY_PREF_UPDATE_NETWORKS is not set
    if (!mSharedPreferences.contains(Const.KEY_PREF_UPDATE_NETWORKS)) {
        Set<String> fallbackUpdateNetworks = new HashSet<String>();
        if (mSharedPreferences.getBoolean(Const.KEY_PREF_UPDATE_WIFI, false)) {
            fallbackUpdateNetworks.add(Const.KEY_PREF_UPDATE_NETWORKS_WIFI);
        }//w ww.j  ava2 s .com
        SharedPreferences.Editor spEditor = mSharedPreferences.edit();
        spEditor.putStringSet(Const.KEY_PREF_UPDATE_NETWORKS, fallbackUpdateNetworks);
        spEditor.commit();
    }

    // by default, show GPS and network location in map
    if (!mSharedPreferences.contains(Const.KEY_PREF_LOC_PROV)) {
        Set<String> defaultLocProvs = new HashSet<String>(
                Arrays.asList(new String[] { LocationManager.GPS_PROVIDER, LocationManager.NETWORK_PROVIDER }));
        SharedPreferences.Editor spEditor = mSharedPreferences.edit();
        spEditor.putStringSet(Const.KEY_PREF_LOC_PROV, defaultLocProvs);
        spEditor.commit();
    }
}

From source file:kn.uni.gis.foxhunt.GameActivity.java

private void registerOnGPS() {
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    if (!!!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        startActivity(intent);/* www .  j  a  v  a  2 s  . c o m*/
    }
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 500, 2f, this);
    if (SettingsContext.getInstance().isUseNetwork()) {
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 500, 2f, this);
    }
}

From source file:com.mobicage.rogerthat.GetLocationActivity.java

@Override
protected void onServiceBound() {
    T.UI();//w w w .  ja  v  a  2s  . co m
    setContentView(R.layout.get_location);

    mProgressDialog = new ProgressDialog(this);
    mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    mProgressDialog.setMessage(getString(R.string.updating_location));
    mProgressDialog.setCancelable(true);
    mProgressDialog.setCanceledOnTouchOutside(true);
    mProgressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            T.UI();
            if (mLocationManager != null) {
                try {
                    mLocationManager.removeUpdates(mLocationListener);
                } catch (SecurityException e) {
                    L.bug(e); // Should never happen
                }
            }
        }
    });
    mProgressDialog.setMax(10000);

    mUseGPS = (CheckBox) findViewById(R.id.use_gps_provider);
    mGetCurrentLocationButton = (Button) findViewById(R.id.get_current_location);
    mAddress = (EditText) findViewById(R.id.address);
    mCalculate = (Button) findViewById(R.id.calculate);

    mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    if (mLocationManager == null) {
        mGetCurrentLocationButton.setEnabled(false);
    } else {
        mUseGPS.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked && !mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
                    new AlertDialog.Builder(GetLocationActivity.this).setMessage(R.string.gps_is_not_enabled)
                            .setPositiveButton(R.string.yes, new SafeDialogInterfaceOnClickListener() {
                                @Override
                                public void safeOnClick(DialogInterface dialog, int which) {
                                    Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                                    startActivityForResult(intent, TURNING_ON_GPS);
                                }
                            }).setNegativeButton(R.string.no, new SafeDialogInterfaceOnClickListener() {
                                @Override
                                public void safeOnClick(DialogInterface dialog, int which) {
                                    mUseGPS.setChecked(false);
                                }
                            }).create().show();
                }
            }
        });

        mGetCurrentLocationButton.setOnClickListener(new SafeViewOnClickListener() {
            @Override
            public void safeOnClick(View v) {
                T.UI();
                if (mService.isPermitted(Manifest.permission.ACCESS_FINE_LOCATION)) {
                    getMyLocation();
                } else {
                    ActivityCompat.requestPermissions(GetLocationActivity.this,
                            new String[] { Manifest.permission.ACCESS_FINE_LOCATION },
                            PERMISSION_REQUEST_ACCESS_FINE_LOCATION);
                }
            }
        });
    }

    mCalculate.setOnClickListener(new SafeViewOnClickListener() {
        @Override
        public void safeOnClick(View v) {
            final ProgressDialog pd = new ProgressDialog(GetLocationActivity.this);
            pd.setProgressStyle(ProgressDialog.STYLE_SPINNER);
            pd.setMessage(getString(R.string.updating_location));
            pd.setCancelable(false);
            pd.setIndeterminate(true);
            pd.show();
            final String addressText = mAddress.getText().toString();
            mService.postOnIOHandler(new SafeRunnable() {
                @Override
                protected void safeRun() throws Exception {
                    Geocoder geoCoder = new Geocoder(GetLocationActivity.this, Locale.getDefault());
                    try {
                        List<Address> addresses = geoCoder.getFromLocationName(addressText, 5);
                        if (addresses.size() > 0) {
                            Address address = addresses.get(0);
                            final Location location = new Location("");
                            location.setLatitude(address.getLatitude());
                            location.setLongitude(address.getLongitude());
                            mService.postOnUIHandler(new SafeRunnable() {
                                @Override
                                protected void safeRun() throws Exception {
                                    pd.dismiss();
                                    mLocation = location;
                                    showMap();
                                }
                            });
                            return;
                        }
                    } catch (IOException e) {
                        L.d("Failed to geo code address " + addressText, e);
                    }
                    mService.postOnUIHandler(new SafeRunnable() {
                        @Override
                        protected void safeRun() throws Exception {
                            pd.dismiss();
                            UIUtils.showLongToast(GetLocationActivity.this,
                                    getString(R.string.failed_to_lookup_address));
                        }
                    });
                }
            });
        }
    });
}

From source file:com.amazonaws.devicefarm.android.referenceapp.Fragments.FixturesFragment.java

/**
 * Updates the GPS status/*from  w  w w.j a v a  2s  . co m*/
 */
private void updateGPSStatusDisplay() {
    final LocationManager locationManager = (LocationManager) getActivity()
            .getSystemService(Context.LOCATION_SERVICE);
    gps.setText(Boolean.toString(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)));
}

From source file:fr.louisbl.cordova.gpslocation.CordovaGPSLocation.java

private boolean isGPSdisabled() {
    boolean gps_enabled;
    try {//from  w  ww.j  av  a  2 s . c  om
        gps_enabled = mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
    } catch (Exception ex) {
        ex.printStackTrace();
        gps_enabled = false;
    }

    return !gps_enabled;
}

From source file:com.rareventure.android.GpsReader.java

public void turnOn() {
    synchronized (lock) {
        //          Log.d(GpsTrailerService.TAG,"Turning on gps");
        if (!lm.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
            GTG.alert(GTGEvent.ERROR_GPS_DISABLED);
            return;
        }/*from   w ww.ja v  a  2s  .c  o m*/
        if (ActivityCompat.checkSelfPermission(this.ctx,
                Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            GTG.alert(GTGEvent.ERROR_GPS_NO_PERMISSION);
            //            Log.d(GpsTrailerService.TAG,"Failed no permission");
            return;
        }

        if (gpsOn) {
            //            Log.d(GpsTrailerService.TAG,"Gps already on");
            return; //already on
        }
        gpsOn = true;

        //         Log.d(GpsTrailerService.TAG,"Really turning on");
        Criteria criteria = new Criteria();
        criteria.setSpeedRequired(false);
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
        criteria.setAltitudeRequired(false);
        criteria.setBearingRequired(false);
        criteria.setCostAllowed(false);

        String providerName = lm.getBestProvider(criteria, true);
        lm.requestLocationUpdates(providerName, prefs.gpsRecurringTimeMs, 0, locationListener, looper);
    }
}

From source file:com.cmput301w17t07.moody.EditMoodActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    UserController userController = new UserController();
    userName = userController.readUsername(EditMoodActivity.this).toString();
    setContentView(R.layout.activity_edit_mood);
    setUpMenuBar(this);

    // get the mood object that was selected
    Intent intent = getIntent();//from   w  ww . j  a v a  2  s  . com
    editMood = (Mood) intent.getSerializableExtra("editMood");
    date = editMood.getDate();
    bitmapImage = (Bitmap) intent.getParcelableExtra("bitmapback");
    editBitmapImage = bitmapImage;
    deletedPic = (int) intent.getExtras().getInt("bitmapdelete");
    latitude = editMood.getLatitude();
    longitude = editMood.getLongitude();
    image = (ImageView) findViewById(R.id.editImageView);
    final TextView location = (TextView) findViewById(R.id.locationText);
    address = editMood.getDisplayLocation();
    location.setText(address);

    if (latitude == 0 && longitude == 0) {
        location1 = null;
    }
    displayAttributes();
    if (deletedPic == 1) {
        image.setImageBitmap(null);
    }

    //set up the button and imageButton
    ImageButton editLocation = (ImageButton) findViewById(R.id.location);
    editLocation.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            locationText = (TextView) findViewById(R.id.locationText);
            locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
            //check available tools
            List<String> locationList = locationManager.getProviders(true);
            if (locationList.contains(LocationManager.GPS_PROVIDER)) {
                provider = LocationManager.GPS_PROVIDER;
            } else if (locationList.contains(LocationManager.NETWORK_PROVIDER)) {
                provider = LocationManager.NETWORK_PROVIDER;
            } else {
                Toast.makeText(getApplicationContext(), "Please check your permissions", Toast.LENGTH_LONG)
                        .show();
            }
            //check the permission
            if (ActivityCompat.checkSelfPermission(getApplicationContext(),
                    android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
                    && ActivityCompat.checkSelfPermission(getApplicationContext(),
                            android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                // TODO: Consider calling
                Toast.makeText(getApplicationContext(),
                        "Getting location failed, Please check the application permissions", Toast.LENGTH_SHORT)
                        .show();
                return;
            }

            location1 = locationManager.getLastKnownLocation(provider);
            if (location1 == null) {
                latitude = 0;
                longitude = 0;
            } else {
                latitude = location1.getLatitude();
                longitude = location1.getLongitude();
            }

            //get the location name by latitude and longitude
            Geocoder gcd = new Geocoder(EditMoodActivity.this, Locale.getDefault());
            try {
                List<Address> addresses = gcd.getFromLocation(latitude, longitude, 1);

                if (addresses.size() > 0)
                    address = "  " + addresses.get(0).getFeatureName() + " "
                            + addresses.get(0).getThoroughfare() + ", " + addresses.get(0).getLocality() + ", "
                            + addresses.get(0).getAdminArea() + ", " + addresses.get(0).getCountryCode();
                location.setText(address);
            } catch (Exception e) {
                e.printStackTrace();
            }

            final ImageButton deleteLocation = (ImageButton) findViewById(R.id.deleteLocation);
            deleteLocation.setVisibility(View.VISIBLE);
            deleteLocation.setEnabled(true);
        }
    });

    editLocation.setOnLongClickListener(new View.OnLongClickListener() {
        public boolean onLongClick(View view) {
            moodMessage_text = Description.getText().toString();
            editMood.setMoodMessage(moodMessage_text);
            editMood.setDate(date);
            Intent editLocation = new Intent(EditMoodActivity.this, EditLocation.class);
            editLocation.putExtra("EditMood", editMood);
            editLocation.putExtra("bitmap", compress(editBitmapImage));
            startActivity(editLocation);
            return true;
        }
    });

    final ImageButton deleteLocation = (ImageButton) findViewById(R.id.deleteLocation);
    deleteLocation.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            location1 = null;
            locationText = (TextView) findViewById(R.id.locationText);
            address = null;
            locationText.setText(address);
            latitude = 0;
            longitude = 0;
            deleteLocation.setVisibility(View.INVISIBLE);
            deleteLocation.setEnabled(false);
        }
    });

    ImageButton editCameraButton = (ImageButton) findViewById(R.id.editCamera);
    editCameraButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            try {
                Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
                startActivityForResult(intent, 1);
            } catch (Exception e) {
                Intent intent = new Intent(getApplicationContext(), EditMoodActivity.class);
                startActivity(intent);
            }
        }
    });

    editCameraButton.setOnLongClickListener(new View.OnLongClickListener() {
        public boolean onLongClick(View view) {
            try {
                Intent intent = new Intent("android.intent.action.PICK");
                intent.setType("image/*");
                startActivityForResult(intent, 0);
            } catch (Exception e) {
                Intent intent = new Intent(getApplicationContext(), EditMoodActivity.class);
                startActivity(intent);
            }
            return true;
        }
    });

    ImageButton PickerButton = (ImageButton) findViewById(R.id.EditDate);
    PickerButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            innit();
            TimeDialog.show();
        }
    });
    Button submitButton = (Button) findViewById(R.id.button5);
    submitButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            moodMessage_text = Description.getText().toString();
            MoodController moodController = new MoodController();
            editBitmapImage = bitmapImage;
            AchievementManager.initManager(EditMoodActivity.this);
            AchievementController achievementController = new AchievementController();
            achievements = achievementController.getAchievements();
            achievements.firstTimeEditFlag = 1;
            achievementController.saveAchievements();

            if (!moodController.editMood(EmotionText, userName, moodMessage_text, latitude, longitude,
                    editBitmapImage, SocialSituation, date, address, editMood, EditMoodActivity.this)) {
                Toast.makeText(EditMoodActivity.this, "Mood message length is too long. Please try again",
                        Toast.LENGTH_SHORT).show();
            } else {
                Intent intent = new Intent(EditMoodActivity.this, TimelineActivity.class);
                startActivity(intent);
                finish();
            }
        }
    });

    // TODO button needs only display when image present in Mood
    final ImageButton deletePicture = (ImageButton) findViewById(R.id.deletePicture);
    if (editBitmapImage == null || deletedPic == 1) {
        deletePicture.setVisibility(View.INVISIBLE);
        deletePicture.setEnabled(false);
    }
    deletePicture.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            bitmapImage = null;
            editBitmapImage = null;
            image.setImageDrawable(null);
            deletePicture.setVisibility(View.INVISIBLE);
            deletePicture.setEnabled(false);
        }
    });
}

From source file:com.nextgis.uikobserver.MainActivity.java

private void requestLocationUpdates() {
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, currentLocationListener);
    locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, currentLocationListener);
}