Search in sources :

Example 76 with LocationManager

use of android.location.LocationManager in project carat by amplab.

the class SamplingLibrary method getBestProvider.

public static String getBestProvider(Context context) {
    LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    Criteria c = new Criteria();
    c.setAccuracy(Criteria.ACCURACY_COARSE);
    c.setPowerRequirement(Criteria.POWER_LOW);
    String provider = lm.getBestProvider(c, true);
    return provider;
}
Also used : LocationManager(android.location.LocationManager) Criteria(android.location.Criteria)

Example 77 with LocationManager

use of android.location.LocationManager in project carat by amplab.

the class Sampler method requestLocationUpdates.

private void requestLocationUpdates() {
    LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    lm.removeUpdates(this);
    List<String> providers = SamplingLibrary.getEnabledLocationProviders(context);
    if (providers != null) {
        for (String provider : providers) {
            lm.requestLocationUpdates(provider, Constants.FRESHNESS_TIMEOUT, 0, this);
        // Log.v(TAG, "Location updates requested for " + provider);
        }
    }
}
Also used : LocationManager(android.location.LocationManager)

Example 78 with LocationManager

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

the class PostActivity method updateLocation.

private void updateLocation() {
    LocationManager locationManager = (LocationManager) getApplicationContext().getSystemService(LOCATION_SERVICE);
    disposable.add(new LocationSingleBuilder(Objects.requireNonNull(locationManager)).getSingle().subscribe(it -> {
        model.getUpdateStatus().setLocation(new Pair<>(it.getLatitude(), it.getLongitude()));
        locationText.setText(getString(R.string.lat_and_lon, it.getLatitude(), it.getLongitude()));
    }, this::errorNotify));
}
Also used : LocationManager(android.location.LocationManager) Rect(android.graphics.Rect) Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) Pair(kotlin.Pair) Uri(android.net.Uri) ImageView(android.widget.ImageView) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) ActionBar(androidx.appcompat.app.ActionBar) Manifest(android.Manifest) CheckBox(android.widget.CheckBox) RequestManager(com.bumptech.glide.RequestManager) LocationSingleBuilder(com.github.moko256.twitlatte.rx.LocationSingleBuilder) View(android.view.View) Schedulers(io.reactivex.schedulers.Schedulers) AdapterView(android.widget.AdapterView) RecyclerView(androidx.recyclerview.widget.RecyclerView) ContextCompat(androidx.core.content.ContextCompat) PostStatusModelImpl(com.github.moko256.twitlatte.model.impl.PostStatusModelImpl) NoSpanInputFilterKt(com.github.moko256.twitlatte.text.NoSpanInputFilterKt) Objects(java.util.Objects) DpToPxKt(com.github.moko256.twitlatte.view.DpToPxKt) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Unit(kotlin.Unit) TextView(android.widget.TextView) PostStatusModel(com.github.moko256.twitlatte.model.base.PostStatusModel) ImageKeyboardEditText(com.github.moko256.twitlatte.widget.ImageKeyboardEditText) Emoji(com.github.moko256.latte.client.base.entity.Emoji) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) LocationManager(android.location.LocationManager) Snackbar(com.google.android.material.snackbar.Snackbar) TextWatcher(android.text.TextWatcher) Context(android.content.Context) KeyEvent(android.view.KeyEvent) AlertDialog(androidx.appcompat.app.AlertDialog) ArraysKt(kotlin.collections.ArraysKt) Intent(android.content.Intent) CLIENT_TYPE_TWITTER(com.github.moko256.latte.client.twitter.TwitterApiClientImplKt.CLIENT_TYPE_TWITTER) Single(io.reactivex.Single) Editable(android.text.Editable) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) ClipData(android.content.ClipData) PermissionChecker(androidx.core.content.PermissionChecker) SuppressLint(android.annotation.SuppressLint) Menu(android.view.Menu) Parcelable(android.os.Parcelable) ActivityCompat(androidx.core.app.ActivityCompat) Client(com.github.moko256.twitlatte.entity.Client) VerifyCredentialOnSubscribe(com.github.moko256.twitlatte.rx.VerifyCredentialOnSubscribe) Spinner(android.widget.Spinner) Glide(com.bumptech.glide.Glide) TypedValue(android.util.TypedValue) EditText(android.widget.EditText) CLIENT_TYPE_MASTODON(com.github.moko256.latte.client.mastodon.MastodonApiClientImplKt.CLIENT_TYPE_MASTODON) LocationSingleBuilder(com.github.moko256.twitlatte.rx.LocationSingleBuilder) Pair(kotlin.Pair)

Example 79 with LocationManager

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

the class PlacePickerActivity method onStop.

@Override
protected void onStop() {
    super.onStop();
    if (locationListener != null) {
        LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        locationManager.removeUpdates(locationListener);
        locationListener = null;
    }
}
Also used : LocationManager(android.location.LocationManager)

Example 80 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 = Settings.Global.getInt(context.getContentResolver(), Settings.Global.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)

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