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.qasp.diego.arsp.LocalizacaoGPSService.java

@Override
public void onCreate() {
    lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    ll = new MeuLocationListener();
}

From source file:com.vrjco.v.demo.MainActivity.java

private void initialize_Layout() {
    tvlat = (TextView) findViewById(R.id.tv_lat);
    tvlongi = (TextView) findViewById(R.id.tv_longi);
    tvtestlat = (TextView) findViewById(R.id.test_lat);
    tvtestlongi = (TextView) findViewById(R.id.test_longi);
    tvSameLocation = (TextView) findViewById(R.id.check_loc);
    bStart = (Button) findViewById(R.id.bstart);
    bTest = (Button) findViewById(R.id.btest);
    test_is_set = false;/*w ww  .  j  a  v a 2s  .  c o  m*/
    lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    logLocationListener = new LogLocationListener();
    testLocationListener = new TestLocationListener();
    handler = new Handler(getMainLooper());
    //noinspection deprecation
    sp = new SoundPool(1, AudioManager.STREAM_ALARM, 0);
    beep_sound = sp.load(getApplicationContext(), R.raw.beep, 1);
}

From source file:de.grobox.liberario.StationsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);

    // remember view for UI changes when fragment is not active
    mView = inflater.inflate(R.layout.fragment_stations, container, false);

    NetworkProvider np = NetworkProviderFactory.provider(Preferences.getNetworkId(getActivity()));

    if (np.hasCapabilities(Capability.DEPARTURES)) {
        setDeparturesView();/*from www  .  j  a  v a 2s.  c o  m*/
    } else {
        LinearLayout departuresLayout = (LinearLayout) mView.findViewById(R.id.departuresLayout);
        departuresLayout.setVisibility(View.GONE);
    }

    if (np.hasCapabilities(Capability.NEARBY_STATIONS)) {
        setNearbyStationsView();
    } else {
        LinearLayout nearbyStationsLayout = (LinearLayout) mView.findViewById(R.id.nearbyStationsLayout);
        nearbyStationsLayout.setVisibility(View.GONE);
    }

    return mView;
}

From source file:com.commonsware.android.service.WeatherPlusService.java

@Override
public void onCreate() {
    super.onCreate();

    client = new DefaultHttpClient();
    format = getString(R.string.url);// w w w. ja  va  2 s.co m

    myLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    myLocationManager.requestLocationUpdates("gps", 10000, 10000.0f, onLocationChange);
}

From source file:ti.modules.titanium.geolocation.TiLocation.java

public TiLocation() {
    locationManager = (LocationManager) TiApplication.getInstance().getSystemService(Context.LOCATION_SERVICE);
    knownProviders = locationManager.getAllProviders();
    mobileId = TiPlatformHelper.getMobileId();
    appGuid = TiApplication.getInstance().getAppInfo().getGUID();
    sessionId = TiPlatformHelper.getSessionId();
    countryCode = Locale.getDefault().getCountry();
    runtimeHandler = new Handler(TiMessenger.getRuntimeMessenger().getLooper(), this);
}

From source file:com.crowdpp.nagisa.crowdpp2.util.LocationTracker.java

public Location getLocation() {
    try {//w  ww. java2s . co m
        locationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);

        // getting GPS status
        isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);

        // getting network status
        isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);

        if (!isGPSEnabled && !isNetworkEnabled) {
            // no network provider is enabled
        } else {
            this.canGetLocation = true;
            // if GPS Enabled get lat/long using GPS Services
            if (isGPSEnabled) {
                if (location == null) {
                    if (ContextCompat.checkSelfPermission(mContext,
                            android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                        Log.i("LocationTracker", "Permission Denied!");
                    }
                    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_TIME_BW_UPDATES,
                            MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
                    Log.i("LocationTracker", "GPS Enabled");
                    if (locationManager != null) {
                        location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
                        if (location != null) {
                            latitude = location.getLatitude();
                            longitude = location.getLongitude();
                        }
                        if (latitude == 0.0 || longitude == 0.0) {//GPS is not available
                            locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
                                    MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
                            Log.i("LocationTracker", "Network Enabled");
                            if (locationManager != null) {
                                location = locationManager
                                        .getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
                                if (location != null) {
                                    latitude = location.getLatitude();
                                    longitude = location.getLongitude();
                                }
                            }
                        }
                    }
                }
            } else {
                if (isNetworkEnabled) {
                    locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
                            MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
                    Log.i("LocationTracker", "Network Enabled");
                    if (locationManager != null) {
                        location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
                        if (location != null) {
                            latitude = location.getLatitude();
                            longitude = location.getLongitude();
                        }
                    }
                }
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    return location;
}

From source file:com.mattprecious.locnotifier.LocationService.java

@Override
public void onCreate() {
    super.onCreate();

    LocationService.isRunning = true;/* w  w  w .j a  v a2 s.  co  m*/
    preferences = PreferenceManager.getDefaultSharedPreferences(this);

    updateRunningNotification();

    int lat = preferences.getInt("dest_lat", 0);
    int lng = preferences.getInt("dest_lng", 0);

    destination = new Location("");
    destination.setLatitude(lat / 1E6);
    destination.setLongitude(lng / 1E6);

    radius = preferences.getFloat("dest_radius", 0);

    notificationManager = (NotificationManager) getApplicationContext()
            .getSystemService(Context.NOTIFICATION_SERVICE);
    locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

    locationListener = new LocationListener() {
        public void onLocationChanged(Location location) {
            Log.d(getClass().getSimpleName(), "Location changed");
            updateLocation(location);
        }

        public void onStatusChanged(String provider, int status, Bundle extras) {
        }

        public void onProviderEnabled(String provider) {
        }

        public void onProviderDisabled(String provider) {
        }
    };

    locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);

    if (preferences.getBoolean("use_gps", false)) {
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
    }

    Log.d(getClass().getSimpleName(), "Watching your location"); // creepy
}

From source file:com.net.rmopenmenu.MainActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

    setContentView(R.layout.fragment_tabs_pager);

    mTabHost = (TabHost) findViewById(android.R.id.tabhost);
    mTabHost.setup();/*from   w  w  w.j a va  2 s.  c  o m*/

    mViewPager = (ViewPager) findViewById(R.id.pager);

    mTabsAdapter = new TabsAdapter(this, mTabHost, mViewPager);

    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

    Bundle b1 = new Bundle();
    b1.putBoolean("menu", true);

    Bundle b2 = new Bundle();
    b2.putBoolean("menu", false);

    mTabsAdapter.addTab(mTabHost.newTabSpec("menu").setIndicator("Menu"), MenuFragment.class, b1);
    mTabsAdapter.addTab(mTabHost.newTabSpec("restaurant").setIndicator("Restaurant"), MenuFragment.class, b2);
    if (savedInstanceState != null) {
        mTabHost.setCurrentTabByTag(savedInstanceState.getString("tab"));
    }

    // Acquire a reference to the system Location Manager
    locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

    // Define a listener that responds to location updates
    locationListener = new LocationListener() {
        public void onStatusChanged(String provider, int status, Bundle extras) {
        }

        public void onProviderEnabled(String provider) {
        }

        public void onProviderDisabled(String provider) {
        }

        @Override
        public void onLocationChanged(Location location) {
            SharedPreferences.Editor editor = prefs.edit();

            editor.putInt("lat", (int) (location.getLatitude() * 1000000));
            editor.putInt("lon", (int) (location.getLongitude() * 1000000));

            editor.commit();
        }
    };

    // Register the listener with the Location Manager to receive location updates
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
    locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
}

From source file:ca.lightseed.winston.WinstonService.java

/**
 * onStart begins the visible lifetime for the activity.
 * This method performs a permissions check: the app requires either coarse or fine
 * location data permissions to have any function.
 * @param intent/*from w  ww.  ja v  a  2 s .c om*/
 * @param startId
 */
@Override
public void onStart(Intent intent, int startId) {
    super.onStart(intent, startId);
    locationManager = (LocationManager) getApplicationContext().getSystemService(Context.LOCATION_SERVICE);

    if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
            || checkSelfPermission(
                    Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 5, listener);
    }

    Toast.makeText(this, "Started Winston tracking service", Toast.LENGTH_SHORT).show();
}