List of usage examples for android.content Context LOCATION_SERVICE
String LOCATION_SERVICE
To view the source code for android.content Context LOCATION_SERVICE.
Click Source Link
From source file:com.geotrackin.gpslogger.GpsLoggingService.java
private void StartPassiveManager() { if (AppSettings.getChosenListeners().contains("passive")) { tracer.debug("Starting passive location listener"); if (passiveLocationListener == null) { passiveLocationListener = new GeneralLocationListener(this, "PASSIVE"); }//from www. j a va2 s . co m passiveLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); passiveLocationManager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, 1000, 0, passiveLocationListener); } }
From source file:com.roamprocess1.roaming4world.ui.messages.MessageActivity.java
private boolean checkGPSEnabled() { // TODO Auto-generated method stub try {// w w w . j a v a2 s .com locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); } catch (Exception ex) { return false; } }
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//from w w w . j ava 2 s .c om 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:edu.usf.cutr.opentripplanner.android.fragments.MainFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { Log.v(OTPApp.TAG, "onActivityCreated"); super.onActivityCreated(savedInstanceState); mApplicationContext = getActivity().getApplicationContext(); mMap = retrieveMap(mMap);//from w w w .j a va 2s .c o m mOTPApp = ((OTPApp) getActivity().getApplication()); mPrefs = PreferenceManager.getDefaultSharedPreferences(mApplicationContext); sLocationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); if (savedInstanceState == null) { SharedPreferences.Editor prefsEditor = mPrefs.edit(); prefsEditor.putBoolean(OTPApp.PREFERENCE_KEY_ORIGIN_IS_MY_LOCATION, true); prefsEditor.putBoolean(OTPApp.PREFERENCE_KEY_DESTINATION_IS_MY_LOCATION, false); prefsEditor.commit(); mBikeTriangleParameters.setSelectedMinValue(OTPApp.BIKE_PARAMETERS_QUICK_DEFAULT_VALUE); mBikeTriangleParameters.setSelectedMaxValue(OTPApp.BIKE_PARAMETERS_FLAT_DEFAULT_VALUE); } /*if (!mMapFailed) { if (mPrefs.getBoolean(OTPApp.PREFERENCE_KEY_SELECTED_CUSTOM_SERVER, false)) { String baseURL = mPrefs.getString(OTPApp.PREFERENCE_KEY_CUSTOM_SERVER_URL, ""); Server s = new Server(baseURL, mApplicationContext); String bounds; setSelectedServer(s, false); if ((bounds = mPrefs.getString(OTPApp.PREFERENCE_KEY_CUSTOM_SERVER_BOUNDS, null)) != null) { s.setBounds(bounds); addBoundariesRectangle(s); } Log.v(OTPApp.TAG, "Now using custom OTP server: " + baseURL); } else { ServersDataSource dataSource = ServersDataSource.getInstance(mApplicationContext); long serverId = mPrefs.getLong(OTPApp.PREFERENCE_KEY_SELECTED_SERVER, 0); if (serverId != 0) { dataSource.open(); Server s = dataSource .getServer(mPrefs.getLong(OTPApp.PREFERENCE_KEY_SELECTED_SERVER, 0)); dataSource.close(); if (s != null) { setSelectedServer(s, false); addBoundariesRectangle(s); Log.v(OTPApp.TAG, "Now using OTP server: " + s.getRegion()); } } } } */ ArrayAdapter<OptimizeSpinnerItem> optimizationAdapter = new ArrayAdapter<OptimizeSpinnerItem>(getActivity(), android.R.layout.simple_list_item_single_choice, new OptimizeSpinnerItem[] { new OptimizeSpinnerItem(getResources().getString(R.string.left_panel_optimization_quick), OptimizeType.QUICK), new OptimizeSpinnerItem(getResources().getString(R.string.left_panel_optimization_safe), OptimizeType.SAFE), new OptimizeSpinnerItem( getResources().getString(R.string.left_panel_optimization_fewest_transfers), OptimizeType.TRANSFERS) }); mDdlOptimization.setAdapter(optimizationAdapter); ArrayAdapter<TraverseModeSpinnerItem> traverseModeAdapter = new ArrayAdapter<TraverseModeSpinnerItem>( getActivity(), android.R.layout.simple_list_item_single_choice, new TraverseModeSpinnerItem[] { new TraverseModeSpinnerItem(getResources().getString(R.string.left_panel_mode_transit), new TraverseModeSet(TraverseMode.TRANSIT, TraverseMode.WALK)), new TraverseModeSpinnerItem(getResources().getString(R.string.left_panel_mode_bus), new TraverseModeSet(TraverseMode.BUSISH, TraverseMode.WALK)), new TraverseModeSpinnerItem(getResources().getString(R.string.left_panel_mode_train), new TraverseModeSet(TraverseMode.TRAINISH, TraverseMode.WALK)), new TraverseModeSpinnerItem(getResources().getString(R.string.left_panel_mode_walk), new TraverseModeSet(TraverseMode.WALK)), new TraverseModeSpinnerItem(getResources().getString(R.string.left_panel_mode_bicycle), new TraverseModeSet(TraverseMode.BICYCLE)), new TraverseModeSpinnerItem( getResources().getString(R.string.left_panel_mode_transit_bicycle), new TraverseModeSet(TraverseMode.TRANSIT, TraverseMode.BICYCLE)) }); mDdlTravelMode.setAdapter(traverseModeAdapter); Server selectedServer = mOTPApp.getSelectedServer(); if (selectedServer != null) { if (!mMapFailed) { mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(getServerCenter(selectedServer), getServerInitialZoom(selectedServer))); } } restoreState(savedInstanceState); if (savedInstanceState == null) { mDdlOptimization.setItemChecked(0, true); mDdlTravelMode.setItemChecked(0, true); showBikeParameters(false); mArriveBy = false; setTextBoxLocation(getResources().getString(R.string.text_box_my_location), true); } if (!mMapFailed) { initializeMapInterface(mMap); } }
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);// ww w . j av 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:gov.sfmta.sfpark.MainScreenActivity.java
void startLocation() { SharedPreferences preferences = getPreferences(MODE_PRIVATE); warningSeen = preferences.getBoolean(WARNING_KEY, false); if (warningSeen) { //once only, ever! return;//from www .ja va 2 s . co m } locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); speed = 0; lastSpeed = 0; thisProvider = LocationManager.GPS_PROVIDER; // Define a listener that responds to location updates locationListener = new LocationListener() { public void onStatusChanged(String provider, int status, Bundle extras) { MYLOG(String.format("onStatusChanged %d", status)); } public void onProviderEnabled(String provider) { MYLOG("onProviderEnabled" + provider); thisProvider = provider; } public void onProviderDisabled(String provider) { MYLOG("onProviderDisabled" + provider); thisProvider = null; } @Override public void onLocationChanged(Location loc) { MYLOG("onLocationChanged"); lastSpeed = speed; if (loc == null) { speed = 0; } else { // speed is returned in meters per second speed = loc.getSpeed(); userLocation = loc; mapView.invalidate(); } // need last speed > threshold as well. if (speed > SPEED_THRESHOLD) { if (lastSpeed > SPEED_THRESHOLD) { SharedPreferences preferences = getPreferences(MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); warningSeen = preferences.getBoolean(WARNING_KEY, false); if (warningSeen == false) { warningSeen = true; editor.putBoolean(WARNING_KEY, warningSeen); editor.commit(); SpeedingViewActivity.present(mapView.getContext()); } } } if (SFparkActivity.DEBUG) { String locStr = String.format("speed:%f last speed:%f, when %d", speed, lastSpeed, System.currentTimeMillis()); debugText.setText(locStr); } } }; locationUpdates(true); }
From source file:com.geotrackin.gpslogger.GpsLoggingService.java
/** * Starts the location manager. There are two location managers - GPS and * Cell Tower. This code determines which manager to request updates from * based on user preference and whichever is enabled. If GPS is enabled on * the phone, that is used. But if the user has also specified that they * prefer cell towers, then cell towers are used. If neither is enabled, * then nothing is requested.// w w w .j a v a2 s.c o m */ private void StartGpsManager() { tracer.debug("GpsLoggingService.StartGpsManager"); GetPreferences(); if (gpsLocationListener == null) { gpsLocationListener = new GeneralLocationListener(this, "GPS"); } if (towerLocationListener == null) { towerLocationListener = new GeneralLocationListener(this, "CELL"); } gpsLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); towerLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); CheckTowerAndGpsStatus(); if (Session.isGpsEnabled() && AppSettings.getChosenListeners().contains("gps")) { tracer.info("Requesting GPS location updates"); // gps satellite based gpsLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, gpsLocationListener); gpsLocationManager.addGpsStatusListener(gpsLocationListener); gpsLocationManager.addNmeaListener(gpsLocationListener); Session.setUsingGps(true); startAbsoluteTimer(); } if (Session.isTowerEnabled() && (AppSettings.getChosenListeners().contains("network") || !Session.isGpsEnabled())) { tracer.info("Requesting tower location updates"); Session.setUsingGps(false); // Cell tower and wifi based towerLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 0, towerLocationListener); startAbsoluteTimer(); } if (!Session.isTowerEnabled() && !Session.isGpsEnabled()) { tracer.info("No provider available"); Session.setUsingGps(false); SetStatus(R.string.gpsprovider_unavailable); SetFatalMessage(R.string.gpsprovider_unavailable); StopLogging(); return; } if (mainServiceClient != null) { mainServiceClient.OnWaitingForLocation(true); Session.setWaitingForLocation(true); } SetStatus(R.string.started); }
From source file:com.uzmap.pkg.uzmodules.uzBMap.UzBMap.java
private boolean isLocationOPen() { LocationManager locationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE); boolean gps = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); return gps;/*ww w . j a v a 2 s. c o m*/ }
From source file:com.adflake.AdFlakeManager.java
/** * Gets the current location.//from w w w . j a v a2 s .co m * * @note If location is not enabled, this method will return null * @return the current location or null if location access is not enabled or * granted by the user. */ public Location getCurrentLocation() { if (_contextReference == null) { return null; } Context context = _contextReference.get(); if (context == null) { return null; } Location location = null; if (context.checkCallingOrSelfPermission( android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); } else if (context.checkCallingOrSelfPermission( android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) { LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); location = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); } return location; }
From source file:com.ushahidi.android.app.ui.phone.ListMapActivity.java
/** Location stuff **/ // Fetches the current location of the device. protected void setDeviceLocation() { mLocationMgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE); // Get last known location from either GPS or Network provider Location loc = null;/*from w ww. j av a 2s . co m*/ boolean netAvail = (mLocationMgr.getProvider(LocationManager.NETWORK_PROVIDER) != null); boolean gpsAvail = (mLocationMgr.getProvider(LocationManager.GPS_PROVIDER) != null); if (gpsAvail) { loc = mLocationMgr.getLastKnownLocation(LocationManager.GPS_PROVIDER); } else if (netAvail) { loc = mLocationMgr.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); } // Just use last location if it's less than 10 minutes old if (loc != null && ((new Date()).getTime() - loc.getTime() < 10 * 60 * 1000)) { onLocationChanged(loc); } else { if (gpsAvail) { mLocationMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); } if (netAvail) { mLocationMgr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this); } } }