Example usage for android.content Context LOCATION_SERVICE

List of usage examples for android.content Context LOCATION_SERVICE

Introduction

In this page you can find the example usage for android.content Context LOCATION_SERVICE.

Prototype

String LOCATION_SERVICE

To view the source code for android.content Context LOCATION_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.location.LocationManager for controlling location updates.

Usage

From source file:com.intel.xdk.geolocation.Geolocation.java

@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    super.initialize(cordova, webView);

    //get convenience reference to activity
    activity = cordova.getActivity();// w w  w  .j  ava  2s .  c om

    locMan = (LocationManager) activity.getSystemService(Context.LOCATION_SERVICE);
    listeners = new Vector<MobiLocationListener>();
}

From source file:com.laocuo.weather.presenter.impl.LocationPresenter.java

public LocationPresenter(Context context) {
    mContext = context;/*w  ww  . j a v a 2 s . com*/
    mLocationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    mLocationListener = new CityLocationListener();
}

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

@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    super.initialize(cordova, webView);
    mLocationManager = (LocationManager) cordova.getActivity().getSystemService(Context.LOCATION_SERVICE);
}

From source file:ch.luethi.skylinestracker.PositionService.java

@Override
public void onCreate() {
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    prefs = new SkyLinesPrefs(this);
    app = ((SkyLinesApp) getApplicationContext());
    intentPosStatus = new Intent(MainActivity.BROADCAST_STATUS);
    intentPosStatus.putExtra(MainActivity.MESSAGE_STATUS_TYPE, MainActivity.MESSAGE_POS_STATUS);
    intentWaitStatus = new Intent(MainActivity.BROADCAST_STATUS);
    intentWaitStatus.putExtra(MainActivity.MESSAGE_STATUS_TYPE, MainActivity.MESSAGE_POS_WAIT_STATUS);
    intentConStatus = new Intent(MainActivity.BROADCAST_STATUS);
    intentConStatus.putExtra(MainActivity.MESSAGE_STATUS_TYPE, MainActivity.MESSAGE_CON_STATUS);
}

From source file:com.jmstudios.redmoon.receiver.LocationUpdateListener.java

@Override
public void onLocationChanged(Location location) {
    if (DEBUG)//from w ww.  jav  a  2 s  .  co  m
        Log.i(TAG, "Location search succeeded");
    LocationManager locationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);
    if (ContextCompat.checkSelfPermission(mContext,
            Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED)
        locationManager.removeUpdates(this);

    String prefKey = mContext.getString(R.string.pref_key_location);
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext);
    SharedPreferences.Editor editor = sp.edit();
    editor.putString(prefKey, location.getLatitude() + "," + location.getLongitude());
    editor.apply();

    if (mPreference != null)
        mPreference.handleLocationFound(location);
}

From source file:com.commonsware.android.internet.WeatherDemo.java

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);/*w  w  w .jav  a 2  s  .  c om*/

    myLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    format = getString(R.string.url);
    browser = (WebView) findViewById(R.id.webkit);
    client = new DefaultHttpClient();
}

From source file:com.dwdesign.tweetings.activity.NearbyMapViewerActivity.java

protected void getLocationAndCenterMap() {
    LocationManager mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    final Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    final String provider = mLocationManager.getBestProvider(criteria, true);

    Location mRecentLocation = null;

    if (provider != null) {
        mRecentLocation = mLocationManager.getLastKnownLocation(provider);
    } else {//from   www  . ja  v a2 s  .c om
        Toast.makeText(this, R.string.cannot_get_location, Toast.LENGTH_SHORT).show();
    }

    if (mRecentLocation != null && isNativeMapSupported()) {
        NativeNearbyMapFragment aFragment = (NativeNearbyMapFragment) mFragment;
        aFragment.setCenter(mRecentLocation);
    }
}

From source file:com.prey.services.LocationService.java

@Override
public void onCreate() {
    PreyLogger.d("LocationService is going to be started...");

    androidLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || (ActivityCompat.checkSelfPermission(this,
            Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
            || ActivityCompat.checkSelfPermission(this,
                    Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED)) {

        LocationProvider gpsLocationProvider = androidLocationManager.getProvider(LocationManager.GPS_PROVIDER);
        LocationProvider networkProvider = androidLocationManager.getProvider(LocationManager.NETWORK_PROVIDER);
        if (gpsLocationProvider != null
                && androidLocationManager.isProviderEnabled(gpsLocationProvider.getName())) {
            androidLocationManager.requestLocationUpdates(gpsLocationProvider.getName(),
                    PreyConfig.UPDATE_INTERVAL, PreyConfig.LOCATION_PROVIDERS_MIN_REFRESH_DISTANCE,
                    gpsLocationListener);
            PreyLogger.d("GPS Location provider has been started.");
        }//from w ww. j av  a 2  s  .  com
        if (networkProvider != null && androidLocationManager.isProviderEnabled(networkProvider.getName())) {
            androidLocationManager.requestLocationUpdates(networkProvider.getName(),
                    PreyConfig.UPDATE_INTERVAL / 4, PreyConfig.LOCATION_PROVIDERS_MIN_REFRESH_DISTANCE,
                    networkLocationListener);
            PreyLogger.d("NETWORK Location provider has been started.");
        }
    } else {
        PreyLogger.i("___________ask for permission LocationService ACCESS_FINE_LOCATION");
    }

    PreyLogger.d("LocationService has been started...");
}

From source file:de.grobox.liberario.ui.LocationInputGPSView.java

public LocationInputGPSView(Activity context, LocationInputViewHolder ui, int caller) {
    super(context, ui, false);

    this.caller = caller;
    this.locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);

    locAdapter.setGPS(true);/*ww w .j  av a2 s .c o m*/
}

From source file:edu.cmu.cs.quiltview.RequestPullingService.java

@Override
public void onCreate() {
    super.onCreate();
    locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
}