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.rareventure.android.GpsReader.java

public GpsReader(DataOutputStream os, Context ctx, GpsProcessor gpsProcessor, String tag, Looper looper) {
    this.ctx = ctx;
    this.os = os;
    this.tag = tag;
    this.gpsProcessor = gpsProcessor;
    this.gpsDataBuffer = new GpsDataBuffer(16);

    this.looper = looper;

    //TODO 3.2: handle multile levels of accuracy
    //basically read from every gps system available
    lm = (LocationManager) ctx.getSystemService(Context.LOCATION_SERVICE);

}

From source file:com.nextgis.mobile.services.TrackerService.java

@Override
public void onCreate() {
    Log.d(TAG, "onCreate()");
    super.onCreate();

    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    trackerLocationListener = new TrackerLocationListener();
}

From source file:com.precisionag.waterplane.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.field);
    MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
    GoogleMap map = mapFragment.getMap();
    map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
    map.setMyLocationEnabled(true);//w w  w  .ja  v  a  2 s  .c om
    map.setOnMapClickListener(this);
    map.setOnMarkerClickListener(onMarkerClickListener);

    field = new Field(bitmap, new LatLng(0.0, 0.0), new LatLng(0.0, 0.0), 0.0, 0.0);
    markers = new ArrayList<Marker>();
    mode = 0;

    readDataFile(field);
    prevoverlay = field.createOverlay(map);
    configSeekbar(field, prevoverlay);
    LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
}

From source file:com.nextgis.uikobserver.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mFillDataHandler = new Handler() {
        public void handleMessage(Message msg) {
            Bundle resultData = msg.getData();
            boolean bHaveErr = resultData.getBoolean("error");
            if (bHaveErr) {
                Toast.makeText(MainActivity.this, getResources().getText(R.string.sFailed), Toast.LENGTH_LONG)
                        .show();//from www . ja v  a 2  s. com
            } else {
                Toast.makeText(MainActivity.this, getResources().getText(R.string.sSuccess), Toast.LENGTH_LONG)
                        .show();
            }
        };
    };

    sendButton = (Button) findViewById(R.id.sendDataBtn);
    sendButton.setEnabled(false);
    sendButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            SendData();
        }
    });

    tvLoc = (TextView) findViewById(R.id.locationString);

    tvUIK = (TextView) findViewById(R.id.uikNo);
    tvEMail = (TextView) findViewById(R.id.userMail);
    tvNote = (TextView) findViewById(R.id.notesString);

    locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    currentLocationListener = new CurrentLocationListener();

    dfLon = 200;
    dfLat = 200;

    sN = (String) getResources().getText(R.string.compas_N);
    sS = (String) getResources().getText(R.string.compas_S);
    sW = (String) getResources().getText(R.string.compas_W);
    sE = (String) getResources().getText(R.string.compas_E);

    sCoordLat = (String) getResources().getText(R.string.coord_lat);
    sCoordLon = (String) getResources().getText(R.string.coord_lon);

    //sUIK, sMail, sNote

    requestLocationUpdates();
}

From source file:com.adampmarshall.speedo.LocationActivity.java

/**
 * This sample demonstrates how to incorporate location based services in
 * your app and process location updates. The app also shows how to convert
 * lat/long coordinates to human-readable addresses.
 *///from  w  w  w  . j  ava 2 s  . c  om
@SuppressLint("NewApi")
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Restore apps state (if exists) after rotation.
    if (savedInstanceState != null) {
        mUseFine = savedInstanceState.getBoolean(KEY_FINE);
        mUseBoth = savedInstanceState.getBoolean(KEY_BOTH);
    } else {
        mUseFine = false;
        mUseBoth = true;
    }
    mSpeed = (TextView) findViewById(R.id.speed);
    Typeface font = Typeface.createFromAsset(getAssets(), "DS-DIGI.TTF");
    mSpeed.setTypeface(font);

    // The isPresent() helper method is only available on Gingerbread or
    // above.
    mGeocoderAvailable = Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD && Geocoder.isPresent();

    // Handler for updating text fields on the UI like the lat/long and
    // address.
    mHandler = new Handler() {
        public void handleMessage(Message msg) {
            switch (msg.what) {
            case UPDATE_SPEED:
                mSpeed.setText((String) msg.obj);
                break;
            }
        }
    };
    // Get a reference to the LocationManager object.
    mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    mGmeterView = (GmeterView) findViewById(R.id.gmeter);

}

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

@Override
public void onReceive(Context context, Intent intent) {
    if (DEBUG)/* www.ja  v  a2  s .c o m*/
        Log.i(TAG, "Alarm received");
    FilterCommandSender commandSender = new FilterCommandSender(context);
    FilterCommandFactory commandFactory = new FilterCommandFactory(context);
    Intent onCommand = commandFactory.createCommand(ScreenFilterService.COMMAND_ON);
    Intent pauseCommand = commandFactory.createCommand(ScreenFilterService.COMMAND_PAUSE);

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    SettingsModel settingsModel = new SettingsModel(context.getResources(), sharedPreferences);

    boolean turnOn = intent.getData().toString().equals("turnOnIntent");

    if (turnOn) {
        commandSender.send(onCommand);
        cancelTurnOnAlarm(context);
        scheduleNextOnCommand(context);
    } else {
        commandSender.send(pauseCommand);
        cancelPauseAlarm(context);
        scheduleNextPauseCommand(context);

        // We want to dismiss the notification if the filter is paused
        // automatically.
        // However, the filter fades out and the notification is only
        // refreshed when this animation has been completed.  To make sure
        // that the new notification is removed we create a new runnable to
        // be excecuted 100 ms after the filter has faded out.
        Handler handler = new Handler();

        DismissNotificationRunnable runnable = new DismissNotificationRunnable(context);
        handler.postDelayed(runnable, ScreenFilterPresenter.FADE_DURATION_MS + 100);
    }

    if (settingsModel.getAutomaticFilterMode().equals("sun")) {
        // Update times for the next time (fails silently)
        LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
        if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)
                && ContextCompat.checkSelfPermission(context,
                        Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
            LocationListener listener = new LocationUpdateListener(context);
            locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, listener);
        }
    }
}

From source file:com.samknows.measurement.schedule.datacollection.LocationDataCollector.java

@Override
public void start(TestContext tc) {
    super.start(tc);
    locations = Collections.synchronizedList(new ArrayList<Location>());
    manager = (LocationManager) tc.getSystemService(Context.LOCATION_SERVICE);

    locationType = AppSettings.getInstance().getLocationServiceType();
    //if the provider in the settings is gps but the service is not enable fail over to network provider
    if (locationType == LocationType.gps && !manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        locationType = LocationType.network;
    }// ww w  . j a  v  a2  s .c o  m

    if (locationType != LocationType.gps && locationType != LocationType.network) {
        throw new RuntimeException("unknown location type: " + locationType);
    }

    String provider = locationType == LocationType.gps ? LocationManager.GPS_PROVIDER
            : LocationManager.NETWORK_PROVIDER;

    if (getLastKnown) {
        lastKnown = manager.getLastKnownLocation(provider);
        if (lastKnown != null) {
            data.add(new LocationData(true, lastKnown, locationType));
            lastKnownLocation = locationToDCSString("LASTKNOWNLOCATION", lastKnown);
        }
    }
    gotLastLocation = false;
    manager.requestLocationUpdates(provider, 0, 0, LocationDataCollector.this, Looper.getMainLooper());
    Logger.d(this, "start collecting location data from: " + provider);

    try {
        Logger.d(this, "sleeping: " + time);
        Thread.sleep(time);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    //stop listening for location updates if we are on network. That is done because network location uses network and breaks NetworkCondition
    if (locationType == LocationType.network) {
        manager.removeUpdates(this);
    }
}

From source file:com.metinkale.prayerapp.vakit.AddCity.java

@SuppressWarnings("MissingPermission")
@Override//from w  w w.j  av  a2 s . com
protected void onDestroy() {
    if (PermissionUtils.get(this).pLocation) {
        LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        lm.removeUpdates(this);
    }
    super.onDestroy();
}

From source file:com.nextgis.mobile.forms.CameraFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    setRetainInstance(true);/*from  w  w  w  .  j  av a2 s.c om*/

    View view = inflater.inflate(R.layout.camfragment, container, false);

    Button button = (Button) view.findViewById(R.id.insert_take_photo);
    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            onCapturePhoto();
        }
    });

    ListView photoList = (ListView) view.findViewById(R.id.poi_photos_list);

    adapter = new SimpleAdapter(view.getContext(), listItems, R.layout.row, new String[] { IMG_NAME, IMG_ROT, },
            new int[] { R.id.image_name, R.id.image_rotation });

    photoList.setAdapter(adapter);

    final LocationManager locationManager = (LocationManager) getActivity()
            .getSystemService(Context.LOCATION_SERVICE);

    if (currentLocation == null) {
        currentLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        if (currentLocation == null) {
            currentLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        }
    }
    long now = System.currentTimeMillis();
    declination = CompassFragment.getDeclination(currentLocation, now);

    sensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE);

    return view;
}

From source file:com.example.beyondar.BeyondarLocationManagerMapActivity.java

public void setupMap() {
    if (mMap == null) {
        return;//from w  w  w.j  a  va  2 s.c o  m
    }

    // We create the world and fill the world
    mWorld = CustomWorldHelper.generateObjects(this);

    // As we want to use GoogleMaps, we are going to create the plugin and
    // attach it to the World
    mGoogleMapPlugin = new GoogleMapWorldPlugin(this);
    // Then we need to set the map in to the GoogleMapPlugin
    mGoogleMapPlugin.setGoogleMap(mMap);
    // Now that we have the plugin created let's add it to our world.
    // NOTE: It is better to load the plugins before start adding object in
    // to the world.
    mWorld.addPlugin(mGoogleMapPlugin);

    mMap.setOnMarkerClickListener(this);

    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mGoogleMapPlugin.getLatLng(), 15));
    mMap.animateCamera(CameraUpdateFactory.zoomTo(19), 2000, null);

    // Lets add the user position to the map
    GeoObject user = new GeoObject(1000l);
    user.setGeoPosition(mWorld.getLatitude(), mWorld.getLongitude());
    user.setImageResource(R.drawable.flag);
    user.setName("User position");
    mWorld.addBeyondarObject(user);

    BeyondarLocationManager.addWorldLocationUpdate(mWorld);
    BeyondarLocationManager.addGeoObjectLocationUpdate(user);

    // We need to set the LocationManager to the BeyondarLocationManager.
    BeyondarLocationManager.setLocationManager((LocationManager) getSystemService(Context.LOCATION_SERVICE));
}