List of usage examples for android.location LocationManager GPS_PROVIDER
String GPS_PROVIDER
To view the source code for android.location LocationManager GPS_PROVIDER.
Click Source Link
From source file:com.ptts.fragments.BusLocation.java
@Override protected void onStart() { super.onStart(); if (locationManager != null) { boolean gpsIsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); boolean networkIsEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); if (gpsIsEnabled) { locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000L, 10F, this); } else if (networkIsEnabled) { locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5000L, 10F, this); } else {// w w w.j ava 2s . c om //Show an error dialog that GPS is disabled... Log.i("NO GPS", "GPS is off"); } } }
From source file:info.snowhow.plugin.RecorderService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { Log.i(LOG_TAG, "Received start id " + startId + ": " + intent); if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { showNoGPSAlert();/* w w w . ja v a 2 s. c o m*/ } runningID = startId; // We want this service to continue running until it is explicitly // stopped, so return sticky. if (intent == null) { tf = sharedPref.getString("runningTrackFile", ""); Log.w(LOG_TAG, "Intent is null, trying to continue to write to file " + tf + " lm " + locationManager); minimumPrecision = sharedPref.getFloat("runningPrecision", 0); distanceChange = sharedPref.getLong("runningDistanceChange", MINIMUM_DISTANCE_CHANGE_FOR_UPDATES); updateTime = sharedPref.getLong("runningUpdateTime", MINIMUM_TIME_BETWEEN_UPDATES); updateTimeFast = sharedPref.getLong("runningUpdateTimeFast", MINIMUM_TIME_BETWEEN_UPDATES_FAST); speedLimit = sharedPref.getLong("runningSpeedLimit", SPEED_LIMIT); adaptiveRecording = sharedPref.getBoolean("adaptiveRecording", false); int count = sharedPref.getInt("count", 0); if (count > 0) { firstPoint = false; } if (tf == null || tf == "") { Log.e(LOG_TAG, "No trackfile found ... exit clean here"); cleanUp(); return START_NOT_STICKY; } } else { tf = intent.getStringExtra("fileName"); Log.d(LOG_TAG, "FILENAME for recording is " + tf); minimumPrecision = intent.getFloatExtra("precision", 0); distanceChange = intent.getLongExtra("distance_change", MINIMUM_DISTANCE_CHANGE_FOR_UPDATES); updateTime = intent.getLongExtra("update_time", MINIMUM_TIME_BETWEEN_UPDATES); updateTimeFast = intent.getLongExtra("update_time_fast", MINIMUM_TIME_BETWEEN_UPDATES_FAST); speedLimit = intent.getLongExtra("speed_limit", SPEED_LIMIT); adaptiveRecording = intent.getBooleanExtra("adaptiveRecording", false); editor.putString("runningTrackFile", tf); editor.putFloat("runningPrecision", minimumPrecision); editor.putLong("runningDistanceChange", distanceChange); editor.putLong("runningUpdateTime", updateTime); editor.putLong("runningUpdateTimeFast", updateTimeFast); editor.putLong("runningSpeedLimit", speedLimit); editor.putBoolean("adaptiveRecording", adaptiveRecording); editor.commit(); } Intent cordovaMainIntent; try { PackageManager packageManager = this.getPackageManager(); cordovaMainIntent = packageManager.getLaunchIntentForPackage(this.getPackageName()); Log.d(LOG_TAG, "got cordovaMainIntent " + cordovaMainIntent); if (cordovaMainIntent == null) { throw new PackageManager.NameNotFoundException(); } } catch (PackageManager.NameNotFoundException e) { cordovaMainIntent = new Intent(); } PendingIntent pend = PendingIntent.getActivity(this, 0, cordovaMainIntent, 0); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, new Intent(ifString), 0); NotificationCompat.Action stop = new NotificationCompat.Action.Builder(android.R.drawable.ic_delete, "Stop recording", pendingIntent).build(); note = new NotificationCompat.Builder(this).setContentTitle(applicationName + " GPS tracking") .setSmallIcon(android.R.drawable.ic_menu_mylocation).setOngoing(true).setContentIntent(pend) .setContentText("No location yet."); note.addAction(stop); nm = (NotificationManager) getSystemService(Activity.NOTIFICATION_SERVICE); nm.notify(0, note.build()); recording = true; Log.d(LOG_TAG, "recording in handleIntent"); try { // create directory first, if it does not exist File trackFile = new File(tf).getParentFile(); if (!trackFile.exists()) { trackFile.mkdirs(); Log.d(LOG_TAG, "done creating path for trackfile: " + trackFile); } Log.d(LOG_TAG, "going to create RandomAccessFile " + tf); myWriter = new RandomAccessFile(tf, "rw"); if (intent != null) { // start new file // myWriter.setLength(0); // delete all contents from file String trackName = intent.getStringExtra("trackName"); String trackHead = initTrack(trackName).toString(); myWriter.write(trackHead.getBytes()); // we want to write JSON manually for streamed writing myWriter.seek(myWriter.length() - 1); myWriter.write(",\"coordinates\":[]}".getBytes()); } } catch (IOException e) { Log.d(LOG_TAG, "io error. cannot write to file " + tf); } locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, updateTime, distanceChange, mgpsll); if (locationManager.getAllProviders().contains(LocationManager.NETWORK_PROVIDER)) { locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, updateTime, distanceChange, mnetll); } return START_STICKY; }
From source file:com.nextgis.maplibui.service.TrackerService.java
@Override public void onCreate() { super.onCreate(); mHasGPSFix = false;//from ww w. j a v a2 s .com mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); mAlarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); IGISApplication application = (IGISApplication) getApplication(); String authority = application.getAuthority(); mContentUriTracks = Uri.parse("content://" + authority + "/" + TrackLayer.TABLE_TRACKS); mContentUriTrackPoints = Uri.parse("content://" + authority + "/" + TrackLayer.TABLE_TRACKPOINTS); mPoint = new GeoPoint(); mValues = new ContentValues(); SharedPreferences sharedPreferences = getSharedPreferences(getPackageName() + "_preferences", Constants.MODE_MULTI_PROCESS); mSharedPreferencesTemp = getSharedPreferences(TEMP_PREFERENCES, MODE_PRIVATE); String minTimeStr = sharedPreferences.getString(SettingsConstants.KEY_PREF_TRACKS_MIN_TIME, "2"); String minDistanceStr = sharedPreferences.getString(SettingsConstants.KEY_PREF_TRACKS_MIN_DISTANCE, "10"); long minTime = Long.parseLong(minTimeStr) * 1000; float minDistance = Float.parseFloat(minDistanceStr); mTicker = getString(R.string.tracks_running); mSmallIcon = R.drawable.ic_action_maps_directions_walk; Intent intentSplit = new Intent(this, TrackerService.class); intentSplit.setAction(ACTION_SPLIT); mSplitService = PendingIntent.getService(this, 0, intentSplit, PendingIntent.FLAG_UPDATE_CURRENT); mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (!PermissionUtil.hasPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) || !PermissionUtil.hasPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION)) return; mLocationManager.addGpsStatusListener(this); String provider = LocationManager.GPS_PROVIDER; if (mLocationManager.getAllProviders().contains(provider)) { mLocationManager.requestLocationUpdates(provider, minTime, minDistance, this); if (Constants.DEBUG_MODE) Log.d(Constants.TAG, "Tracker service request location updates for " + provider); } provider = LocationManager.NETWORK_PROVIDER; if (mLocationManager.getAllProviders().contains(provider)) { mLocationManager.requestLocationUpdates(provider, minTime, minDistance, this); if (Constants.DEBUG_MODE) Log.d(Constants.TAG, "Tracker service request location updates for " + provider); } NotificationHelper.showLocationInfo(this); }
From source file:com.example.get_location.Get_location.java
private void setup() { Location gpsLocation = null;// w w w. ja va 2s. c o m Location networkLocation = null; mLocationManager.removeUpdates(listener); mLatLng.setText(R.string.unknown); mAddress.setText(R.string.unknown); // Get fine location updates only. if (mUseFine) { mFineProviderButton.setBackgroundResource(R.drawable.ic_launcher); mBothProviderButton.setBackgroundResource(R.drawable.ic_launcher); // Request updates from just the fine (gps) provider. gpsLocation = requestUpdatesFromProvider(LocationManager.GPS_PROVIDER, R.string.not_support_gps); // Update the UI immediately if a location is obtained. if (gpsLocation != null) updateUILocation(gpsLocation); } else if (mUseBoth) { // Get coarse and fine location updates. mFineProviderButton.setBackgroundResource(R.drawable.ic_launcher); mBothProviderButton.setBackgroundResource(R.drawable.ic_launcher); // Request updates from both fine (gps) and coarse (network) providers. gpsLocation = requestUpdatesFromProvider(LocationManager.GPS_PROVIDER, R.string.not_support_gps); networkLocation = requestUpdatesFromProvider(LocationManager.NETWORK_PROVIDER, R.string.not_support_network); // If both providers return last known locations, compare the two and use the better // one to update the UI. If only one provider returns a location, use it. if (gpsLocation != null && networkLocation != null) { updateUILocation(getBetterLocation(gpsLocation, networkLocation)); } else if (gpsLocation != null) { updateUILocation(gpsLocation); } else if (networkLocation != null) { updateUILocation(networkLocation); } } }
From source file:com.kentli.cycletrack.RecordingService.java
public void resumeRecording() { this.state = STATE_RECORDING; lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); }
From source file:com.barak.pix.NewPostActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_new_post); // find the retained fragment on activity restarts FragmentManager fm = getSupportFragmentManager(); mTaskFragment = (NewPostUploadTaskFragment) fm.findFragmentByTag(TAG_TASK_FRAGMENT); // create the fragment and data the first time if (mTaskFragment == null) { // add the fragment mTaskFragment = new NewPostUploadTaskFragment(); fm.beginTransaction().add(mTaskFragment, TAG_TASK_FRAGMENT).commit(); }// ww w .j ava2 s . c o m mImageView = (ImageView) findViewById(R.id.new_post_picture); mImageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showImagePicker(); } }); Bitmap selectedBitmap = mTaskFragment.getSelectedBitmap(); Bitmap thumbnail = mTaskFragment.getThumbnail(); if (selectedBitmap != null) { mImageView.setImageBitmap(selectedBitmap); mResizedBitmap = selectedBitmap; } if (thumbnail != null) { mThumbnail = thumbnail; } final EditText descriptionText = (EditText) findViewById(R.id.new_post_text); mSubmitButton = (Button) findViewById(R.id.new_post_submit); mSubmitButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { if (mResizedBitmap == null) { Toast.makeText(NewPostActivity.this, " !!!", Toast.LENGTH_SHORT).show(); return; } if (mLocation == null) { Toast.makeText(NewPostActivity.this, " ? ?", Toast.LENGTH_SHORT) .show(); return; } String postText = descriptionText.getText().toString(); if (TextUtils.isEmpty(postText)) { descriptionText.setError(getString(R.string.error_required_field)); return; } showProgressDialog(getString(R.string.post_upload_progress_message)); mSubmitButton.setEnabled(false); Long timestamp = System.currentTimeMillis(); String bitmapPath = "https://pictures-e88fc.firebaseio.com" + "/" + FirebaseUtil.getCurrentUserId() + "/full/" + timestamp.toString() + "/"; String thumbnailPath = "https://pictures-e88fc.firebaseio.com" + "/" + FirebaseUtil.getCurrentUserId() + "/thumb/" + timestamp.toString() + "/"; mTaskFragment.uploadPost(mResizedBitmap, bitmapPath, mThumbnail, thumbnailPath, mFileUri.getLastPathSegment(), postText, mLocation.getLatitude(), mLocation.getLongitude()); } }); locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locationListener = new MyLocationListener(); if (checkPermission(Manifest.permission.ACCESS_COARSE_LOCATION, getApplicationContext(), NewPostActivity.this)) { locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 10, locationListener); } else { requestPermission(android.Manifest.permission.ACCESS_COARSE_LOCATION, 11, getApplicationContext(), this); } }
From source file:com.boundlessgeo.spatialconnect.scutilities.LocationHelper.java
/** * Convenience method to check if the GPS * @return// ww w. j a va 2s . c o m */ public boolean isGPSPermissionGranted() { return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) && ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED; }
From source file:de.grundid.plusrad.MainActivity.java
private void proccessWithLocationPermission() { final LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { buildAlertMessageNoGps();/*from ww w. ja v a2 s . co m*/ } else { startActivity(new Intent(this, RecordingActivity.class)); } }
From source file:ch.hesso.master.sweetcity.activity.report.ReportActivity.java
private void submitReport() { if (bitmapPicture == null) { DialogUtils.show(ReportActivity.this, "To submit a report, you need to take an representative image."); return;// w ww .j a va 2s.co m } if (this.currentLocation == null) { LocationManager locationManager = (LocationManager) ReportActivity.this .getSystemService(LOCATION_SERVICE); this.currentLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (this.currentLocation == null) { DialogUtils.show(ReportActivity.this, "Unable to get your current location."); return; } } Report newReport = new Report(); newReport.setLatitude((float) this.currentLocation.getLatitude()); newReport.setLongitude((float) this.currentLocation.getLongitude()); newReport.setSubmitDate(new DateTime(new Date())); newReport.setUser(AuthUtils.getAccount()); newReport.setListTag(new ArrayList(tagList.values())); ReportCallbackImpl callback = new ReportCallbackWithResult(ReportActivity.this); new AddReportAsyncTask(this, callback, AuthUtils.getCredential(), newReport, bitmapPicture).execute(); }
From source file:com.cianmcgovern.android.ShopAndShare.Share.java
@Override public void onCreate(Bundle savedInstanceState) { mContext = this; super.onCreate(savedInstanceState); setContentView(R.layout.share);//ww w. ja va2s . c om Button upload = (Button) findViewById(R.id.uploadButton); upload.setText(R.string.upload); upload.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String userLoc = mLocationEdit.getText().toString(); String userStore = mStore.getText().toString(); // Don't allow empty text fields if (userLoc.length() > 1 && userStore.length() > 1) { runUpload(Results.getInstance(), userLoc, userStore); } else new AlertDialog.Builder(mContext).setTitle(R.string.invalidInput) .setMessage(R.string.invalidFields).show(); } }); Button cancel = (Button) findViewById(R.id.cancelShareButton); cancel.setText(R.string.cancelButton); cancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mLocationListener != null) mLocationManager.removeUpdates(mLocationListener); finish(); } }); mLocationEdit = (EditText) findViewById(R.id.enterLocation); mLocationEdit.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if ((event.getAction()) == KeyEvent.ACTION_DOWN && (keyCode == KeyEvent.KEYCODE_ENTER)) { InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); in.hideSoftInputFromWindow(mLocationEdit.getApplicationWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); return true; } return false; } }); mStore = (EditText) findViewById(R.id.enterStore); mStore.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if ((event.getAction()) == KeyEvent.ACTION_DOWN && (keyCode == KeyEvent.KEYCODE_ENTER)) { InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); in.hideSoftInputFromWindow(mStore.getApplicationWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); return true; } return false; } }); mSearch = (Button) findViewById(R.id.locationButton); mSearch.setBackgroundResource(R.drawable.search); mSearch.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mLocationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE); if (!CheckFeatures.haveGPS()) { new AlertDialog.Builder(mContext).setTitle("GPS Required") .setMessage("You must have GPS to use this feature").show(); } // Only use GPS if it is enabled else if (mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { mSearch.setEnabled(false); mSearch.setBackgroundResource(R.drawable.world); getLocation(); } else { mGpsDialog = new AlertDialog.Builder(mContext).create(); mGpsDialog.setTitle(R.string.gpsDisabled); mGpsDialog.setMessage(mContext.getText(R.string.gpsDisabledMessage)); mGpsDialog.show(); } } }); }