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.remdo.app.MainActivity.java
private Boolean isGPSorNetworkEnabled() { Boolean enabled = false;/*from ww w . j a va 2 s. c o m*/ //Accedemos a los servicios de localizacin del sistema LocationManager locationManager = (LocationManager) this.getSystemService(LOCATION_SERVICE); //Obtenemos el estado del GPS y de la red Boolean isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); Boolean isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); if (isGPSEnabled || isNetworkEnabled) enabled = true; return enabled; }
From source file:com.code19.library.SystemUtils.java
/** * <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> *//*from w ww . j a va2s .c o m*/ public static boolean isGpsEnabled(Context context) { LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); return lm.isProviderEnabled(LocationManager.GPS_PROVIDER); }
From source file:com.ibuildapp.romanblack.FanWallPlugin.FanWallPlugin.java
private void initializeBackend() { // parse input xml data res = getResources();/*from w w w .j a v a2s . c om*/ density = res.getDisplayMetrics().density; showProgress = AnimationUtils.loadAnimation(FanWallPlugin.this, R.anim.show_progress_anim); hideProgress = AnimationUtils.loadAnimation(FanWallPlugin.this, R.anim.hide_progress_anim); currentIntent = getIntent(); widget = (Widget) currentIntent.getSerializableExtra("Widget"); String tempCachePath = widget.getCachePath(); EntityParser parser = new EntityParser(); try { if (TextUtils.isEmpty(widget.getPluginXmlData())) { if (TextUtils.isEmpty(currentIntent.getStringExtra("WidgetFile"))) { handler.sendEmptyMessageDelayed(INITIALIZATION_FAILED, 3000); return; } } if (!TextUtils.isEmpty(widget.getPluginXmlData())) { parser.parse(widget.getPluginXmlData()); } else { String xmlData = readXmlFromFile(currentIntent.getStringExtra("WidgetFile")); parser.parse(xmlData); } } catch (Exception e) { handler.sendEmptyMessageDelayed(INITIALIZATION_FAILED, 3000); return; } Statics.hasAd = widget.isHaveAdvertisement(); Statics.appName = widget.getAppName(); Statics.near = parser.getNear(); Statics.MODULE_ID = parser.getModuleId(); Statics.canEdit = parser.getCanEdit(); Statics.APP_ID = parser.getAppId(); Statics.color1 = parser.getColor1(); Statics.color2 = parser.getColor2(); Statics.color3 = parser.getColor3(); Statics.color4 = parser.getColor4(); Statics.color5 = parser.getColor5(); if (Statics.BackColorToFontColor(Statics.color1) == Color.WHITE) Statics.isSchemaDark = true; else Statics.isSchemaDark = false; // init cache path if (!TextUtils.isEmpty(tempCachePath)) Statics.cachePath = tempCachePath + "/fanwall-" + widget.getOrder(); Statics.onAuthListeners.add(this); // register separate LocationManager.GPS_PROVIDER for register status change events locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Statics.currentLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 0, new LocationListener() { @Override public void onLocationChanged(Location location) { Statics.currentLocation = location; } @Override public void onStatusChanged(String s, int i, Bundle bundle) { } @Override public void onProviderEnabled(String s) { Prefs.with(FanWallPlugin.this).save(Prefs.KEY_GPS, true); enableGpsCheckbox.setChecked(true); } @Override public void onProviderDisabled(String s) { Prefs.with(FanWallPlugin.this).save(Prefs.KEY_GPS, false); enableGpsCheckbox.setChecked(false); } }); }
From source file:com.towson.wavyleaf.Sighting.java
protected void refresh() { // Check for GPS LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); playAPKEnabled = doesDeviceHaveGooglePlayServices(); currentEditableLocation = locationData.getLocation(); if (!isAccurateLocation(currentEditableLocation)) { // If location isn't accurate if (!gpsEnabled) { // If GPS is disabled buildAlertMessageNoGps();/*from w w w. j ava 2s .c om*/ } else if (gpsEnabled) { if (playAPKEnabled) { setUpMapIfNeeded(); wheresWaldo(); } } updateLocationTimer = new Timer(); TimerTask updateLocationTask = new TimerTask() { @Override public void run() { checkLocation(); } }; updateLocationTimer.scheduleAtFixedRate(updateLocationTask, 0, FIVE_SECONDS); } else setUpMapIfNeeded(); }
From source file:com.androzic.location.LocationService.java
private void connect() { locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (locationManager != null) { lastLocationMillis = 0;// www.j av a2s . c o m pause = 1; isContinous = false; justStarted = true; smoothSpeed = 0.0f; avgSpeed = 0.0f; locationManager.addGpsStatusListener(this); if (useNetwork) { try { locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this); Log.d(TAG, "Network provider set"); } catch (IllegalArgumentException e) { Toast.makeText(this, getString(R.string.err_no_network_provider), Toast.LENGTH_LONG).show(); } } try { locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); locationManager.addNmeaListener(this); Log.d(TAG, "Gps provider set"); } catch (IllegalArgumentException e) { Log.d(TAG, "Cannot set gps provider, likely no gps on device"); } startForeground(NOTIFICATION_ID, getNotification()); } }
From source file:com.nextgis.rehacompdemo.RoutingActivity.java
@Override public void onLocationChanged(Location currentLocation) { GeoEnvelope area = getArea(currentLocation); Location nextLocation = new Location(LocationManager.GPS_PROVIDER); Location previousLocation = new Location(LocationManager.GPS_PROVIDER); TreeMap<Float, Location> perpendiculars = new TreeMap<>(); HashMap<Location, GeoLineString> snapsToSegments = new HashMap<>(); for (GeoLineString segment : mRouteSegments) if (area.intersects(segment.getEnvelope()) || area.contains(segment.getEnvelope())) { previousLocation.setLongitude(Geo.mercatorToWgs84SphereX(segment.getPoint(0).getX())); previousLocation.setLatitude(Geo.mercatorToWgs84SphereY(segment.getPoint(0).getY())); nextLocation.setLongitude(Geo.mercatorToWgs84SphereX(segment.getPoint(1).getX())); nextLocation.setLatitude(Geo.mercatorToWgs84SphereY(segment.getPoint(1).getY())); Location snap = snapToLine(previousLocation, nextLocation, currentLocation, false); Float perpendicular = currentLocation.distanceTo(snap); perpendiculars.put(perpendicular, snap); snapsToSegments.put(snap, segment); }/*from ww w .j av a 2 s . c o m*/ if (perpendiculars.size() > 0 && snapsToSegments.size() > 0) { Location snappedLocation = perpendiculars.firstEntry().getValue(); GeoLineString segment = snapsToSegments.get(snappedLocation); previousLocation.setLongitude(Geo.mercatorToWgs84SphereX(segment.getPoint(0).getX())); previousLocation.setLatitude(Geo.mercatorToWgs84SphereY(segment.getPoint(0).getY())); nextLocation.setLongitude(Geo.mercatorToWgs84SphereX(segment.getPoint(1).getX())); nextLocation.setLatitude(Geo.mercatorToWgs84SphereY(segment.getPoint(1).getY())); GeoPoint point = segment.getPoint(1); if (snappedLocation.distanceTo(previousLocation) < snappedLocation.distanceTo(nextLocation)) { point = segment.getPoint(0); nextLocation.setLongitude(previousLocation.getLongitude()); nextLocation.setLatitude(previousLocation.getLatitude()); } if (snappedLocation.distanceTo(nextLocation) <= mActivationDistance) { long id = -1; for (IGeometryCacheItem cachePoint : mAllPoints) { if (point.equals(cachePoint.getGeometry())) id = cachePoint.getFeatureId(); } int position = mAdapter.getItemPosition(id); if (position != -1) { mSteps.requestFocusFromTouch(); mSteps.setSelection(position); } } } }
From source file:edu.princeton.jrpalmer.asmlibrary.Settings.java
@Override protected void onResume() { if (Util.trafficCop(this)) finish();/*from w w w .j av a 2 s . c o m*/ IntentFilter uploadFilter; uploadFilter = new IntentFilter( getResources().getString(R.string.internal_message_id) + Util.MESSAGE_FIX_UPLOADED); uploadReceiver = new UploadReceiver(); registerReceiver(uploadReceiver, uploadFilter); IntentFilter fixFilter; fixFilter = new IntentFilter( getResources().getString(R.string.internal_message_id) + Util.MESSAGE_FIX_RECORDED); fixReceiver = new FixReceiver(); registerReceiver(fixReceiver, fixFilter); shareMyData = PropertyHolder.getShareData(); toggleParticipationViews(shareMyData); int nUploads = PropertyHolder.getNUploads(); final long participationTime = PropertyHolder.ptCheck(); participationTimeText.setBase(SystemClock.elapsedRealtime() - participationTime); // service button boolean isServiceOn = PropertyHolder.isServiceOn(); mServiceButton.setChecked(isServiceOn); mServiceButton.setOnClickListener(new ToggleButton.OnClickListener() { public void onClick(View view) { if (view.getId() != R.id.service_button) return; Context context = view.getContext(); boolean on = ((ToggleButton) view).isChecked(); String schedule = on ? Util.MESSAGE_SCHEDULE : Util.MESSAGE_UNSCHEDULE; // Log.e(TAG, schedule + on); // now schedule or unschedule Intent intent = new Intent(getString(R.string.internal_message_id) + schedule); context.sendBroadcast(intent); showSpinner(on, storeMyData); if (on && shareMyData) { final long ptNow = PropertyHolder.ptStart(); participationTimeText.setBase(SystemClock.elapsedRealtime() - ptNow); participationTimeText.start(); ContentResolver ucr = getContentResolver(); ucr.insert(Util.getUploadQueueUri(context), UploadContentValues.createUpload("ONF", "on," + Util.iso8601(System.currentTimeMillis()) + "," + ptNow)); } else { final long ptNow = PropertyHolder.ptStop(); participationTimeText.setBase(SystemClock.elapsedRealtime() - ptNow); participationTimeText.stop(); // stop uploader Intent stopUploaderIntent = new Intent(Settings.this, FileUploader.class); // Stop service if it is currently running stopService(stopUploaderIntent); if (shareMyData) { ContentResolver ucr = getContentResolver(); ucr.insert(Util.getUploadQueueUri(context), UploadContentValues.createUpload("ONF", "off," + Util.iso8601(System.currentTimeMillis()) + "," + ptNow)); } } // If user turns CountdownDisplay on but GPS is not on, remind // user to turn // GPS on if (on) { final LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { if (!manager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { buildAlertMessageNoGpsNoNet(); } else buildAlertMessageNoGps(); } } return; } }); // interval spinner int intspinner_item = android.R.layout.simple_spinner_item; int dropdown_item = android.R.layout.simple_spinner_dropdown_item; ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.interval_array, intspinner_item); adapter.setDropDownViewResource(dropdown_item); mIntervalSpinner.setAdapter(adapter); mIntervalSpinner.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View v, int pos, long id) { int parentId = parent.getId(); if (parentId != R.id.spinner_interval) return; if (pos > mInterval.length) return; if (!PropertyHolder.isServiceOn()) { PropertyHolder.setAlarmInterval(mInterval[pos]); return; } PropertyHolder.setAlarmInterval(mInterval[pos]); mServiceButton.setChecked(true); Intent intent = new Intent(getString(R.string.internal_message_id) + Util.MESSAGE_SCHEDULE); Context context = getApplicationContext(); context.sendBroadcast(intent); showSpinner(true, storeMyData); if (shareMyData) { ContentResolver ucr = getContentResolver(); ucr.insert(Util.getUploadQueueUri(context), UploadContentValues.createUpload("INT", Util.iso8601(System.currentTimeMillis()) + "," + mInterval[pos])); } } public void onNothingSelected(AdapterView<?> parent) { // do nothing } }); int pos = ai2pos(PropertyHolder.getAlarmInterval()); mIntervalSpinner.setSelection(pos); showSpinner(isServiceOn, storeMyData); // mydata buttons // storage spinner storageDays = PropertyHolder.getStorageDays(); mStorageSpinner.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View v, int pos, long id) { int parentId = parent.getId(); if (parentId != R.id.spinner_mydata) return; if (pos > MAX_STORAGE - MIN_STORAGE) return; PropertyHolder.setStorageDays(pos + MIN_STORAGE); PropertyHolder.setStoreMyData((pos + MIN_STORAGE) > 0); } public void onNothingSelected(AdapterView<?> parent) { // do nothing } }); int storagepos = storageDays - MIN_STORAGE; mStorageSpinner.setSelection(storagepos); // NEW STUFF mToggleSatRadioGroup = (RadioGroup) findViewById(R.id.toggleSatRadioGroup); mToggleIconsRadioGroup = (RadioGroup) findViewById(R.id.toggleIconsRadioGroup); mToggleAccRadioGroup = (RadioGroup) findViewById(R.id.toggleAccRadioGroup); mLimitStartDateRadioGroup = (RadioGroup) findViewById(R.id.limitStartDateRadioGroup); mLimitEndDateRadioGroup = (RadioGroup) findViewById(R.id.limitEndDateRadioGroup); Intent i = getIntent(); if (i.getBooleanExtra(MapMyData.DATES_BUTTON_MESSAGE, false)) { RelativeLayout dateSettingsArea = (RelativeLayout) findViewById(R.id.dateSettingsArea); dateSettingsArea.setFocusable(true); dateSettingsArea.setFocusableInTouchMode(true); dateSettingsArea.requestFocus(); } if (shareMyData && isServiceOn) { participationTimeText.setBase(SystemClock.elapsedRealtime() - PropertyHolder.ptStart()); participationTimeText.start(); } nUploadsText.setText(String.valueOf(nUploads)); if (nUploads >= Util.UPLOADS_TO_PRO && !PropertyHolder.getProVersion() && participationTime >= Util.TIME_TO_PRO) { Util.createProNotification(context); PropertyHolder.setProVersion(true); PropertyHolder.setNeedsDebriefingSurvey(true); } boolean proV = PropertyHolder.getProVersion(); // 19 December 2013: end of research changes mShareDataRadioGroup.check(R.id.sharedataNo); mShareDataRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { if (checkedId == R.id.sharedataYes) { buildSharingOverAnnouncement(); } mShareDataRadioGroup.check(R.id.sharedataNo); } }); /* * if (proV) { * * if (shareMyData) { mShareDataRadioGroup.check(R.id.sharedataYes); if * (PropertyHolder.isRegistered() == false || * PropertyHolder.hasConsented() == false) { send2Intro(context); } } * else { mShareDataRadioGroup.check(R.id.sharedataNo); } * * mShareDataRadioGroup .setOnCheckedChangeListener(new * OnCheckedChangeListener() { * * @Override public void onCheckedChanged(RadioGroup group, int * checkedId) { shareMyData = (checkedId == R.id.sharedataYes); * PropertyHolder.setShareData(shareMyData); * toggleParticipationViews(shareMyData); final boolean on = * PropertyHolder.isServiceOn(); if (shareMyData) { if * (PropertyHolder.isRegistered() == false || * PropertyHolder.hasConsented() == false) { send2Intro(context); * * } if (on) { * * final long ptNow = PropertyHolder.ptStart(); * participationTimeText.setBase(SystemClock .elapsedRealtime() - * ptNow); * * participationTimeText.start(); * * ContentResolver ucr = getContentResolver(); * * ucr.insert( Util.getUploadQueueUri(context), * UploadContentValues.createUpload( "ONF", "on," + Util.iso8601(System * .currentTimeMillis()) + "," + ptNow)); * * } } else { * * final long ptNow = PropertyHolder.ptStop(); * participationTimeText.setBase(SystemClock .elapsedRealtime() - * ptNow); participationTimeText.stop(); // stop uploader Intent i = new * Intent(Settings.this, FileUploader.class); // Stop service if it is * currently running stopService(i); * * if (on) { ContentResolver ucr = getContentResolver(); * * ucr.insert( Util.getUploadQueueUri(context), * UploadContentValues.createUpload( "ONF", "off," + Util.iso8601(System * .currentTimeMillis()) + "," + ptNow)); * * } * * } * * } }); } else { mShareDataRadioGroup.check(R.id.sharedataYes); * mShareDataRadioGroup .setOnCheckedChangeListener(new * OnCheckedChangeListener() { * * @Override public void onCheckedChanged(RadioGroup group, int * checkedId) { if (checkedId == R.id.sharedataNo) { * mShareDataRadioGroup.check(R.id.sharedataYes); * showCurrentlySharingDialog(); } } }); * * } */ new CheckPendingUploadsSizeTask().execute(context); new CheckUserDbSizeTask().execute(context); deletePendingUploadsButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ContentResolver cr = getContentResolver(); final int nDeleted = cr.delete(Util.getUploadQueueUri(context), "1", null); // Log.i("Settings", "number of rows deleted=" + nDeleted); Util.toast(context, String.valueOf(nDeleted) + " " + getResources().getString(R.string.locations_deleted) + "."); updateStorageSizes(); } }); deleteUserDbButton = (ImageButton) findViewById(R.id.deleteMyDbButton); deleteUserDbButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ContentResolver cr = getContentResolver(); final int nDeleted = cr.delete(Util.getFixesUri(context), "1", null); Util.toast(context, String.valueOf(nDeleted) + " " + getResources().getString(R.string.locations_deleted) + "."); updateStorageSizes(); } }); uploadButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (Util.isOnline(context)) { Intent i = new Intent(Settings.this, FileUploader.class); startService(i); new UploadMessageTask().execute(context); } else { Util.toast(context, getResources().getString(R.string.offline_warning)); } } }); mToggleSatRadioGroup.check(PropertyHolder.getMapSat() ? R.id.toggleSatYes : R.id.toggleSatNo); mToggleSatRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { PropertyHolder.setMapSat(checkedId == R.id.toggleSatYes); } }); mToggleIconsRadioGroup.check(PropertyHolder.getMapIcons() ? R.id.toggleIconsYes : R.id.toggleIconsNo); mToggleIconsRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { PropertyHolder.setMapIcons(checkedId == R.id.toggleIconsYes); } }); mToggleAccRadioGroup.check(PropertyHolder.getMapAcc() ? R.id.toggleAccYes : R.id.toggleAccNo); mToggleAccRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { PropertyHolder.setMapAcc(checkedId == R.id.toggleAccYes); } }); mStartDateButton = (Button) findViewById(R.id.startDateButton); mEndDateButton = (Button) findViewById(R.id.endDateButton); boolean limitStartDate = PropertyHolder.getLimitStartDate(); boolean limitEndDate = PropertyHolder.getLimitEndDate(); if (!limitStartDate) mStartDateButton.setVisibility(View.GONE); else { mStartDateButton.setVisibility(View.VISIBLE); } if (!limitEndDate) mEndDateButton.setVisibility(View.GONE); else { mEndDateButton.setVisibility(View.VISIBLE); } mLimitStartDateRadioGroup.check(limitStartDate ? R.id.limitStartDateYes : R.id.limitStartDateNo); mLimitStartDateRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { PropertyHolder.setLimitStartDate(checkedId == R.id.limitStartDateYes); if (checkedId != R.id.limitStartDateYes) mStartDateButton.setVisibility(View.GONE); else { mStartDateButton.setVisibility(View.VISIBLE); } } }); mLimitEndDateRadioGroup.check(limitEndDate ? R.id.limitEndDateYes : R.id.limitEndDateNo); mLimitEndDateRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { PropertyHolder.setLimitEndDate(checkedId == R.id.limitEndDateYes); if (checkedId != R.id.limitEndDateYes) mEndDateButton.setVisibility(View.GONE); else { mEndDateButton.setVisibility(View.VISIBLE); } } }); mStartDateButton.setText(Util.userDateNoTime(PropertyHolder.getMapStartDate())); mStartDateButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { DialogFragment newFragment = new StartDatePickerFragment(); newFragment.show(getSupportFragmentManager(), "datePicker"); } }); mEndDateButton.setText(Util.userDateNoTime(PropertyHolder.getMapEndDate())); mEndDateButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { DialogFragment newFragment = new EndDatePickerFragment(); newFragment.show(getSupportFragmentManager(), "datePicker"); } }); if (PropertyHolder.getNeedsDebriefingSurvey()) { buildProAnnouncement(); PropertyHolder.setNeedsDebriefingSurvey(false); } super.onResume(); }
From source file:com.ternup.caddisfly.fragment.LocationFragment.java
/** * Invoked by the "Start Updates" button * Sends a request to start location updates * * @param v The view object associated with this method, in this case a Button. *///from www. j a va2 s . co m public void startUpdates(View v) { // Get Location Manager and check for GPS & Network location services LocationManager lm = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); if (!lm.isProviderEnabled(LocationManager.GPS_PROVIDER) || !lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { // Build the alert dialog AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle("Location Services Not Active"); builder.setMessage("Please enable Location Services and GPS"); builder.setPositiveButton(R.string.ok, 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(); } else { mUpdatesRequested = true; if (servicesConnected()) { // Turn the indefinite activity indicator on mActivityIndicator.setVisibility(View.VISIBLE); mLocationButton.setVisibility(View.GONE); startPeriodicUpdates(); } } }
From source file:org.csp.everyaware.offline.Map.java
@Override protected void onStart() { super.onStart(); // This verification should be done during onStart() because the system calls // this method when the user returns to the activity, which ensures the desired // location provider is enabled each time the activity resumes from the stopped state. LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); final boolean gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); if (!gpsEnabled) { // Build an alert dialog here that requests that the user enable // the location services, then when the user clicks the "OK" button, // call enableLocationSettings() }//from w w w . j a v a 2 s .c om }
From source file:com.nextgis.mobile.MapFragment.java
public void showInfoPane(boolean isShow) { if (isShow) { mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mChangeLocationListener); mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, mChangeLocationListener); mLocationManager.addGpsStatusListener(mGpsStatusListener); final RelativeLayout.LayoutParams RightParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); RightParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); int nHeight = 0; if (mContext.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) { TypedValue typeValue = new TypedValue(); mContext.getTheme().resolveAttribute(android.R.attr.actionBarSize, typeValue, true); nHeight = TypedValue.complexToDimensionPixelSize(typeValue.data, mContext.getResources().getDisplayMetrics()); //getTheme().resolveAttribute(android.R.attr.actionBarSize, typeValue, true); //nHeight = TypedValue.complexToDimensionPixelSize( // typeValue.data,getResources().getDisplayMetrics()); }//w ww . j ava 2 s. c o m RightParams.setMargins(0, 0, 0, nHeight); mMapRelativeLayout.addView(mInfoPane, RightParams); } else { mLocationManager.removeUpdates(mChangeLocationListener); mLocationManager.removeGpsStatusListener(mGpsStatusListener); mMapRelativeLayout.removeView(mInfoPane); } mIsInfoPaneShow = isShow; }