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.kentli.cycletrack.RecordingService.java

public void cancelRecording() {
    if (trip != null) {
        trip.dropTrip();/*  w w w. j  a  v  a2  s.c om*/
    }

    lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    lm.removeUpdates(this);

    clearNotifications();
    this.state = STATE_IDLE;
}

From source file:com.brejza.matt.habmodem.Dsp_service.java

@Override
public IBinder onBind(Intent arg0) {

    if (!isRecording)
        serviceRestart();//from  w ww  .  j  a va  2  s.c o  m
    if (serviceInactiveTimer != null) {
        serviceInactiveTimer.cancel();
        serviceInactiveTimer = null;
        logEvent("Stopping Inactivity Timer", false);
    }

    System.out.println("DEBUG : something bound");

    handler = new Handler();

    //string receiver
    if (headsetReceiver == null)
        headsetReceiver = new HeadsetReceiver();
    IntentFilter intentFilter1 = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
    registerReceiver(headsetReceiver, intentFilter1);

    if (hab_con == null) {
        String call_u = PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext())
                .getString("pref_callsign", "USER");

        hab_con = new Habitat_interface(
                PreferenceManager.getDefaultSharedPreferences(this).getString("pref_habitat_server",
                        "habitat.habhub.org"),
                PreferenceManager.getDefaultSharedPreferences(this).getString("pref_habitat_db", "habitat"),
                new Listener(call_u, new Gps_coordinate(50.2, -0.6, 0), false));
        //hab_con.upload_payload_telem(new Telemetry_string("$$ASTRA,12:12:12,5044.11111,-001.00000,1212,34*1234"));   
        hab_con.addGetActiveFlightsTask();
        hab_con.addHabitatRecievedListener(this);
    }
    if (loc_han == null) {
        loc_han = new Location_handler();
        this.locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    }

    hab_con.device = android.os.Build.BRAND + " " + android.os.Build.MODEL;
    hab_con.device_software = android.os.Build.VERSION.RELEASE;
    hab_con.application = "HAB Modem for Android";
    String vers = "unknown";
    try {
        Context cn = getApplicationContext();
        vers = cn.getPackageManager().getPackageInfo(cn.getPackageName(), 0).versionName;
    } catch (NameNotFoundException e) {
        System.out.println("Cannot get version number - " + e.toString());
    }
    hab_con.application_version = vers;

    //System.out.println("Starting audio");
    return mBinder;
}

From source file:com.airg.android.permission.sample.DangerousFragment.java

@SuppressWarnings("ResourceType")
private void onLocationPermissionGranted() {
    latitude.setText(R.string.loading);//from ww  w .j a  va 2s.co  m
    longitude.setText(R.string.loading);

    final Activity activity = getActivity();
    gps = (LocationManager) activity.getSystemService(Context.LOCATION_SERVICE);
    updateLocation(gps.getLastKnownLocation(LocationManager.NETWORK_PROVIDER));
    gps.requestSingleUpdate(LocationManager.GPS_PROVIDER, this, null);
}

From source file:com.nextgis.mobile.MapFragment.java

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

    mContext = getActivity().getApplicationContext();

    if (mMap == null) {
        MainActivity activity = (MainActivity) getActivity();
        mMap = activity.getMap();//from  w w w .j  av a 2  s  .  co m
        mMap.addListener(this);
    }

    View view = inflater.inflate(R.layout.mapfragment, container, false);
    FrameLayout layout = (FrameLayout) view.findViewById(R.id.mapholder);
    //search relative view of map, if not found - add it
    if (mMap != null) {
        mMapRelativeLayout = (RelativeLayout) layout.findViewById(R.id.maprl);
        if (mMapRelativeLayout != null) {
            mMapRelativeLayout.addView(mMap, new RelativeLayout.LayoutParams(
                    RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT));
            addMapButtons(mMapRelativeLayout);
        } // layout.addView(mMap);//.getRelativeLayout());
    }

    mInfoPane = inflater.inflate(R.layout.infopane, null, true);

    mLocationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);
    mChangeLocationListener = new ChangeLocationListener();
    mGpsStatusListener = new GpsStatusListener();

    return view;
}

From source file:org.klnusbaum.udj.EventListFragment.java

public void onStart() {
    super.onStart();
    lm = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
    List<String> providers = lm.getProviders(false);
    if (providers.contains(LocationManager.GPS_PROVIDER)) {
        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 50, this);
        if (lastKnown == null) {
            lastKnown = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        }//from w  ww .  j a  v  a 2s .  c  o m
    }
    if (providers.contains(LocationManager.NETWORK_PROVIDER)) {
        lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 50, this);
        if (lastKnown == null) {
            lastKnown = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        }
    }
    if (lastSearch == null) {
        lastSearch = new LocationEventSearch(lastKnown);
    }
}

From source file:com.davidmascharka.lips.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        requestMyPermissions();//  ww w  .  j a v  a  2 s . c o  m
    }

    getPreferences();

    setContentView(R.layout.activity_main);

    if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction().add(R.id.container, new MainFragment()).commit();
    }

    rotation = new float[9];
    inclination = new float[9];
    orientation = new float[3];

    sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    locationListener = new LocationListener() {

        @Override
        public void onLocationChanged(Location location) {
            updateLocation(location);
        }

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

        @Override
        public void onProviderEnabled(String provider) {
        }

        @Override
        public void onProviderDisabled(String provider) {
        }
    };

    wifiReadings = new LinkedHashMap<String, Integer>();
    resetWifiReadings(building);

    userInitiatedScan = false;
}

From source file:com.sitewhere.android.example.ExampleFragment.java

/**
 * Only schedule SiteWhere reporting thread once we have a connection to the server.
 */// ww w.ja  v  a2 s . c om
public void startDeviceMonitoring() {
    Log.d(TAG, "Starting device monitoring.");

    getActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {
            // Start location updates.
            boolean locationStarted = false;
            locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
            if (ActivityCompat.checkSelfPermission(getActivity(),
                    Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
                    && ActivityCompat.checkSelfPermission(getActivity(),
                            Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                Log.d(TAG, "No permissions for location. Requesting permissions from user.");
                requestPermissions(new String[] { Manifest.permission.ACCESS_FINE_LOCATION,
                        Manifest.permission.ACCESS_COARSE_LOCATION }, LOCATION_REQUEST_CODE);
                return;
            }
            if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
                locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
                        ExampleFragment.this);
                locationStarted = true;
                Log.d(TAG, "Started monitoring locations via GPS provider.");
            } else if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
                locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0,
                        ExampleFragment.this);
                locationStarted = true;
                Log.d(TAG, "Started monitoring locations via network provider.");
            } else {
                locationStarted = false;
                Log.d(TAG, "No location provider available. Will not monitor location.");
            }

            // Start accelerometer updates.
            boolean accelerometerStarted = false;
            sensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE);
            if (sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) != null) {
                rotationVector = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
                sensorManager.registerListener(ExampleFragment.this, rotationVector,
                        SensorManager.SENSOR_DELAY_NORMAL);
                accelerometerStarted = true;
                Log.d(TAG, "Started monitoring accelerometer.");
            } else {
                Toast.makeText(getActivity().getApplicationContext(),
                        "Unable to start accelerometer updates. No accelerometer provided", Toast.LENGTH_LONG);
                accelerometerStarted = false;
                Log.d(TAG, "Unable to monitor accelerometer.");
            }

            // Send alerts to SiteWhere.
            SiteWhereMessageClient messageClient = SiteWhereMessageClient.getInstance();
            try {
                if (locationStarted)
                    messageClient.sendDeviceAlert(messageClient.getUniqueDeviceId(), "location.started",
                            "Started to read location data.", null);
            } catch (SiteWhereMessagingException ex) {
                Log.e(TAG, "Unable to send location.started alert to SiteWhere.");
            }
            try {
                if (accelerometerStarted)
                    messageClient.sendDeviceAlert(messageClient.getUniqueDeviceId(), "accelerometer.started",
                            "Started to read accelerometer data.", null);
            } catch (SiteWhereMessagingException e) {
                Log.e(TAG, "Unable to send accelerometer.started alert to SiteWhere.");
            }

            if (scheduler != null) {
                scheduler.shutdownNow();
            }
            scheduler = Executors.newSingleThreadScheduledExecutor();
            scheduler.scheduleAtFixedRate(new SiteWhereDataReporter(), SEND_INTERVAL_IN_SECONDS,
                    SEND_INTERVAL_IN_SECONDS, TimeUnit.SECONDS);
            Log.d(TAG, "Set up scheduler for monitoring.");
        }
    });
}

From source file:net.evecom.androidecssp.gps.ResourceItemizedOverlayActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    initData();/*from  w w  w.j a va2 s. c  om*/
    /** 2.2 ***/
    setContentView(R.layout.itemized_resource);
    /** 2.2 ***/
    mMapView = (MapView) findViewById(R.id.itemized_mapview);
    mMapView.setBuiltInZoomControls(true);
    // Overlay
    // mMapView.setDrawOverlayWhenZooming(true);
    mController = mMapView.getController();
    mCon = this;
    // 
    List<Overlay> list = mMapView.getOverlays();
    centerGpsPoint = new GeoPoint((int) (26.031846613632812 * 1E6), (int) (119.4909095748828 * 1E6));
    mController.setCenter(centerGpsPoint);
    sp = instance.getSharedPreferences("GPS", instance.MODE_PRIVATE);
    myLocation = new MyGpsLocationOverlay(this, mMapView,
            new MyGpsLocationOverlay.MyGpsLocationOverlayinterface() {
                @Override
                public void onLocationChanged(Location location, GeoPoint geoPoint) {
                    Editor editor = sp.edit();
                    editor.putString("latitude", "" + location.getLatitude());
                    editor.putString("longitude", "" + location.getLongitude());
                    editor.commit();
                    String strLog = String.format(":\r\n" + ":%f\r\n" + ":%f",
                            location.getLongitude(), location.getLatitude());
                    Toast.makeText(instance, strLog, Toast.LENGTH_SHORT).show();
                    if (!ismanuallocation) {
                        centerGpsPoint = geoPoint;
                    }
                }
            });
    myLocation.enableCompass();
    myLocation.enableMyLocation();
    list.add(myLocation);
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, myLocation);
    } else if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 1, myLocation);
    }

    list.add(new ManualLocationOverlay(this, new ManualLocationOverlay.ManualMapOnCilck() {
        @Override
        public void mapclick(GeoPoint point, MapView mapView) {
            ismanuallocation = true;
            centerGpsPoint = point;
        }
    }));// 

    // initAroundDialog();
    initOtherView();

}

From source file:com.example.mapdemo.TopView.java

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

    mMyLocationCheckbox = (CheckBox) findViewById(R.id.my_location);

    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);

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

    //GeolocationService Locationfetcher = new GeolocationService(,getApplicationContext());
    //locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);

}

From source file:com.keithcassidy.finishline.FinishLineService.java

@Override
public void onCreate() {
    super.onCreate();
    context = this;
    finishLineDataStorage = new FinishLineDataStorage(context);
    finishLineDataStorage.open();/*from ww w .  j  a  v a2s. c o  m*/
    locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    sharedPreferences = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
    sharedPreferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);

    // Require announcementExecutor and splitExecutor to be created.
    sharedPreferenceChangeListener.onSharedPreferenceChanged(sharedPreferences, null);

    lineCrossHandler = new LineCrossHandler();
    lineCrossHandler.setContext(this);
    lineCrossHandler.setFinishLineDataStorage(finishLineDataStorage);
    lineCrossHandler.setMaxAccuracyAllowed(maxAccuracyAllowed);
    lineCrossHandler.setFinishLineExtension(PreferencesUtils.getFinishLineExtension(this));
    lineCrossHandler.setBouys(buoy1, buoy2);
    lineCrossHandler.initialise();

    acquireWakeLock();
    registerLocationListener();

    if (isRacing) {
        Log.v(TAG, "xxx onCreate restartRace service");
        restartRace();
    } else {
        showNotification();
    }

}