Search in sources :

Example 36 with LocationManager

use of android.location.LocationManager in project android_frameworks_base by AOSPA.

the class NetInitiatedActivity method sendUserResponse.

// Respond to NI Handler under GnssLocationProvider, 1 = accept, 2 = deny
private void sendUserResponse(int response) {
    if (DEBUG)
        Log.d(TAG, "sendUserResponse, response: " + response);
    LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    locationManager.sendNiResponse(notificationId, response);
}
Also used : LocationManager(android.location.LocationManager)

Example 37 with LocationManager

use of android.location.LocationManager in project twicalico by moko256.

the class PostActivity method getLocation.

private Single<Location> getLocation() {
    LocationManager locationManager = (LocationManager) getApplicationContext().getSystemService(LOCATION_SERVICE);
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setCostAllowed(false);
    final LocationListener[] locationListener = new LocationListener[1];
    Single<Location> single = Single.create(singleSubscriber -> {
        locationListener[0] = new LocationListener() {

            @Override
            public void onLocationChanged(Location location) {
                locationManager.removeUpdates(this);
                singleSubscriber.onSuccess(location);
            }

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

            @Override
            public void onProviderEnabled(String provider) {
            }

            @Override
            public void onProviderDisabled(String provider) {
            }
        };
        try {
            locationManager.requestSingleUpdate(locationManager.getBestProvider(criteria, true), locationListener[0], null);
        } catch (SecurityException e) {
            singleSubscriber.onError(e);
        }
    });
    single.doOnUnsubscribe(() -> locationManager.removeUpdates(locationListener[0]));
    return single;
}
Also used : LocationManager(android.location.LocationManager) Bundle(android.os.Bundle) LocationListener(android.location.LocationListener) Criteria(android.location.Criteria) GeoLocation(twitter4j.GeoLocation) Location(android.location.Location)

Example 38 with LocationManager

use of android.location.LocationManager in project IITB-App by wncc.

the class MapFragment method getLastKnownLocation.

private Location getLastKnownLocation() {
    // Create a location manager object instance
    LocationManager mLocationManager = (LocationManager) getContext().getSystemService(LOCATION_SERVICE);
    // Get all the different providers which can give current location info
    List<String> providers = mLocationManager.getProviders(true);
    // Initialising the location to be null
    Location bestLocation = null;
    // Creating a for loop to go through all the location providers and get the location
    for (String provider : providers) {
        if (ContextCompat.checkSelfPermission(getContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(getActivity(), new String[] { android.Manifest.permission.ACCESS_COARSE_LOCATION }, MY_PERMISSIONS_REQUEST_LOCATION);
        }
        // Get the last known location from the data provider
        Location l = mLocationManager.getLastKnownLocation(provider);
        // If the last know location provided by the data provider is null then ignore the provider and move to the next one.
        if (l == null) {
            continue;
        }
        if (bestLocation == null || l.getAccuracy() < bestLocation.getAccuracy()) {
            bestLocation = l;
        }
    }
    return bestLocation;
}
Also used : LocationManager(android.location.LocationManager) Location(android.location.Location)

Example 39 with LocationManager

use of android.location.LocationManager in project aware-client by denzilferreira.

the class Aware method complianceStatus.

// public static boolean isServiceRunning(Context context, Class<?> serviceClass) {
// ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
// for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
// if (serviceClass.getName().equals(service.service.getClassName())) {
// return true;
// }
// }
// return false;
// }
private static void complianceStatus(Context context) {
    ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(CONNECTIVITY_SERVICE);
    LocationManager locationManager = (LocationManager) context.getSystemService(LOCATION_SERVICE);
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(TELEPHONY_SERVICE);
    JSONObject complianceStatus = new JSONObject();
    try {
        NetworkInfo active = connManager.getActiveNetworkInfo();
        if (active != null && active.isConnectedOrConnecting()) {
            complianceStatus.put("internet", true);
        } else {
            complianceStatus.put("internet", false);
        }
        NetworkInfo wifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        if (wifi != null && wifi.isAvailable()) {
            complianceStatus.put("wifi", true);
        } else {
            complianceStatus.put("wifi", false);
        }
        NetworkInfo bt = connManager.getNetworkInfo(ConnectivityManager.TYPE_BLUETOOTH);
        if (bt != null && bt.isAvailable()) {
            complianceStatus.put("bt", true);
        } else {
            complianceStatus.put("bt", false);
        }
        NetworkInfo network = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
        if (network != null && network.isAvailable()) {
            complianceStatus.put("network", true);
        } else {
            complianceStatus.put("network", false);
        }
        boolean airplane;
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
            airplane = Settings.Global.getInt(context.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0) != 0;
        } else {
            airplane = Settings.System.getInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) != 0;
        }
        complianceStatus.put("airplane", airplane);
        complianceStatus.put("roaming", telephonyManager.isNetworkRoaming());
        complianceStatus.put("location_gps", locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER));
        complianceStatus.put("location_network", locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER));
        Aware.debug(context, complianceStatus.toString());
    } catch (JSONException e) {
        e.printStackTrace();
    }
}
Also used : LocationManager(android.location.LocationManager) JSONObject(org.json.JSONObject) TelephonyManager(android.telephony.TelephonyManager) NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager) JSONException(org.json.JSONException)

Example 40 with LocationManager

use of android.location.LocationManager in project Klyph by jonathangerbaud.

the class PlacePickerActivity method onStart.

@Override
protected void onStart() {
    super.onStart();
    try {
        Location location = null;
        // Instantiate the default criteria for a location provider
        Criteria criteria = new Criteria();
        // Get a location manager from the system services
        LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        // Get the location provider that best matches the criteria
        String bestProvider = locationManager.getBestProvider(criteria, false);
        if (bestProvider != null) {
            // Get the user's last known location
            location = locationManager.getLastKnownLocation(bestProvider);
            if (locationListener == null) {
                // Set up a location listener if one is not already set
                // up
                // and the selected provider is enabled
                locationListener = new LocationListener() {

                    @Override
                    public void onLocationChanged(Location location) {
                        // On location updates, compare the current
                        // location to the desired location set in the
                        // place picker
                        float distance = location.distanceTo(placePickerFragment.getLocation());
                        if (distance >= LOCATION_CHANGE_THRESHOLD) {
                            placePickerFragment.setLocation(location);
                            placePickerFragment.setRadiusInMeters(SEARCH_RADIUS_METERS);
                            placePickerFragment.setSearchText(SEARCH_TEXT);
                            placePickerFragment.setResultsLimit(SEARCH_RESULT_LIMIT);
                            placePickerFragment.loadData(true);
                        }
                    }

                    @Override
                    public void onStatusChanged(String s, int i, Bundle bundle) {
                    }

                    @Override
                    public void onProviderEnabled(String s) {
                    }

                    @Override
                    public void onProviderDisabled(String s) {
                    }
                };
                locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1, LOCATION_CHANGE_THRESHOLD, locationListener);
            }
        }
        if (location == null) {
            // Todo : set default location the last saved location
            location = SAN_FRANCISCO_LOCATION;
        }
        if (location != null) {
            // Configure the place picker: search center, radius,
            // query, and maximum results.
            placePickerFragment.setLocation(location);
            placePickerFragment.setRadiusInMeters(SEARCH_RADIUS_METERS);
            placePickerFragment.setSearchText(SEARCH_TEXT);
            placePickerFragment.setResultsLimit(SEARCH_RESULT_LIMIT);
            // Start the API call
            placePickerFragment.loadData(true);
        }
    /*
			 * else { // If no location found, show an error
			 * onError(getResources().getString(R.string.no_location_error),
			 * true); }
			 */
    } catch (Exception ex) {
        onError(ex);
    }
}
Also used : LocationManager(android.location.LocationManager) Bundle(android.os.Bundle) LocationListener(android.location.LocationListener) Criteria(android.location.Criteria) FacebookException(com.facebook.FacebookException) Location(android.location.Location)

Aggregations

LocationManager (android.location.LocationManager)74 Location (android.location.Location)33 Bundle (android.os.Bundle)24 LocationListener (android.location.LocationListener)23 BluetoothAdapter (android.bluetooth.BluetoothAdapter)12 Criteria (android.location.Criteria)9 IntentFilter (android.content.IntentFilter)5 TrackerDataHelper (com.android.locationtracker.data.TrackerDataHelper)5 IOException (java.io.IOException)3 SuppressLint (android.annotation.SuppressLint)2 Intent (android.content.Intent)2 SensorManager (android.hardware.SensorManager)2 ConnectivityManager (android.net.ConnectivityManager)2 TelephonyManager (android.telephony.TelephonyManager)2 FacebookException (com.facebook.FacebookException)2 LatLng (com.google.android.gms.maps.model.LatLng)2 Prefs (nodomain.freeyourgadget.gadgetbridge.util.Prefs)2 ActivityManager (android.app.ActivityManager)1 AlarmManager (android.app.AlarmManager)1 KeyguardManager (android.app.KeyguardManager)1