Search in sources :

Example 46 with LocationManager

use of android.location.LocationManager in project JavaForFun by gumartinm.

the class NextActivity method onCreate.

/**
 * Called when the activity is first created.
 */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    CookieSyncManager.createInstance(this);
    myCookie = CookieManager.getInstance().getCookie("192.168.1.34/userfront.php");
    setContentView(R.layout.main2);
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setAltitudeRequired(false);
    criteria.setBearingAccuracy(Criteria.NO_REQUIREMENT);
    criteria.setBearingRequired(false);
    criteria.setCostAllowed(false);
    criteria.setHorizontalAccuracy(Criteria.ACCURACY_HIGH);
    criteria.setPowerRequirement(Criteria.POWER_MEDIUM);
    criteria.setSpeedAccuracy(Criteria.ACCURACY_LOW);
    criteria.setSpeedRequired(true);
    criteria.setVerticalAccuracy(Criteria.NO_REQUIREMENT);
    // Acquire a reference to the system Location Manager
    LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    // Define a listener that responds to location updates
    LocationListener locationListener = new LocationListener() {

        public void onLocationChanged(Location location) {
            // Called when a new location is found by the network location provider.
            makeUseOfNewLocation(location);
        }

        public void onStatusChanged(String provider, int status, Bundle extras) {
        // 1. Fin out the provider state. (see Copilot.java code GPSLocationListener)
        // 2. If it is TEMPORARILY_UNAVAILABLE:
        // 2.1. locationManager.removeUpdates(locationListener); <--- Stop wasting GPS or GSM connections
        // 2.2. Launch Timer with TimerTask 30 or 60 seconds before to enable the locationManager to find out if the provider status changed.
        // 3. If OUT_OF_SERVICE
        // 3.1. locationManager.removeUpdates(locationListener); <--- Stop wasting GPS or GSM connections
        // 3.2. Launch Timer with TimerTask 30 or 60 seconds before to enable the locationManager to find out if the provider status changed.
        // 4. If AVAILABLE
        // Nothing to do here.
        // Just when we are in the second or third point we have to stop draining battery because it is useless.
        }

        public void onProviderEnabled(String provider) {
        }

        public void onProviderDisabled(String provider) {
        }
    };
    // Register the listener with the Location Manager to receive location updates
    locationManager.requestLocationUpdates(0, 10, criteria, locationListener, null);
}
Also used : LocationManager(android.location.LocationManager) Bundle(android.os.Bundle) LocationListener(android.location.LocationListener) Criteria(android.location.Criteria) Location(android.location.Location)

Example 47 with LocationManager

use of android.location.LocationManager in project android-sdk-examples by IndoorAtlas.

the class MapsOverlayActivity method startListeningPlatformLocations.

private void startListeningPlatformLocations() {
    LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    if (locationManager != null) {
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
    }
}
Also used : IALocationManager(com.indooratlas.android.sdk.IALocationManager) LocationManager(android.location.LocationManager)

Example 48 with LocationManager

use of android.location.LocationManager in project android-sdk-examples by IndoorAtlas.

the class WayfindingOverlayActivity method startListeningPlatformLocations.

private void startListeningPlatformLocations() {
    LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    if (locationManager != null && (ActivityCompat.checkSelfPermission(this, ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED)) {
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
    }
}
Also used : IALocationManager(com.indooratlas.android.sdk.IALocationManager) LocationManager(android.location.LocationManager)

Example 49 with LocationManager

use of android.location.LocationManager in project actor-platform by actorapp.

the class MapPickerActivity method setUpMap.

/**
 * This is where we can add markers or lines, add listeners or move the camera. In this case, we
 * just add a marker near Africa.
 * <p/>
 * This should only be called once and when we are sure that {@link #mMap} is not null.
 */
private void setUpMap() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, PERMISSION_REQ_LOCATION);
            im.actor.runtime.Log.d("Permissions", "MapPickerActivity.setUpMap - no permission :c");
            return;
        }
    }
    LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    for (String provider : locationManager.getAllProviders()) {
        currentLocation = locationManager.getLastKnownLocation(provider);
        if (currentLocation != null) {
            break;
        }
    }
    if (currentLocation != null) {
        mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude()), 14));
        fetchPlaces(null);
    }
    mMap.setOnMyLocationChangeListener(this);
    mMap.getUiSettings().setMyLocationButtonEnabled(false);
    mMap.getUiSettings().setZoomControlsEnabled(false);
    mMap.getUiSettings().setCompassEnabled(false);
    mMap.setMyLocationEnabled(true);
    mMap.setOnMapLongClickListener(this);
    mMap.setOnMarkerClickListener(this);
}
Also used : LocationManager(android.location.LocationManager) LatLng(com.google.android.gms.maps.model.LatLng)

Example 50 with LocationManager

use of android.location.LocationManager in project joynr by bmwcarit.

the class MyLocation method getLocation.

/**
 * Get the location of the device
 *
 * @param context
 *            The android application environment
 * @param result
 *            Callback that is called when the location is obtained
 * @return true if the attempt to obtain the location starts successfully, false otherwise
 */
public boolean getLocation(Context context, LocationResult result) {
    locationResult = result;
    if (lm == null)
        lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    // exceptions will be thrown if provider is not permitted.
    try {
        gps_enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
    } catch (Exception ex) {
    }
    try {
        network_enabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
    } catch (Exception ex) {
    }
    // don't start listeners if no provider is enabled
    if (!gps_enabled && !network_enabled)
        return false;
    if (gps_enabled)
        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListenerGps);
    if (network_enabled)
        lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListenerNetwork);
    // Set a timer, if this elapses without locationListenerGps or locationListenerNetwork being called
    // then use the last known location
    timer1 = new Timer();
    timer1.schedule(new GetLastLocation(), 20000);
    return true;
}
Also used : LocationManager(android.location.LocationManager) Timer(java.util.Timer)

Aggregations

LocationManager (android.location.LocationManager)151 Location (android.location.Location)51 Bundle (android.os.Bundle)33 LocationListener (android.location.LocationListener)29 Criteria (android.location.Criteria)21 Intent (android.content.Intent)20 BluetoothAdapter (android.bluetooth.BluetoothAdapter)15 View (android.view.View)10 SuppressLint (android.annotation.SuppressLint)9 IOException (java.io.IOException)9 ConnectivityManager (android.net.ConnectivityManager)7 WifiManager (android.net.wifi.WifiManager)7 TextView (android.widget.TextView)7 DialogInterface (android.content.DialogInterface)6 IntentFilter (android.content.IntentFilter)6 SharedPreferences (android.content.SharedPreferences)6 PendingIntent (android.app.PendingIntent)5 NetworkInfo (android.net.NetworkInfo)5 TelephonyManager (android.telephony.TelephonyManager)5 TrackerDataHelper (com.android.locationtracker.data.TrackerDataHelper)5