LocationManager Wrapper for Android

Overview

Locationmanager

AndroidStudio minSDK

Locationmanager is a small wrapper for Location Tracker.

Installation

  • Add jitpackto your repositories in Project build.gradle :
allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
    ...
}
  • Add dependency :
implementation 'com.github.grumpyshoe:android-module-locationmanager:1.3.0'

Usage

  • Get instance of LocationManager:
val locationManager : LocationManager = LocationManagerImpl()

In order to locate your device, the library will request the permissions android.permission.ACCESS_FINE_LOCATION and android.permission.ACCESS_COARSE_LOCATION. To handle to permission request result correctly delegate the response of onRequestPermissionsResult in your activity to the library like this:

override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
    locationManager.onRequestPermissionsResult(requestCode, permissions, grantResults)
            ?: super.onRequestPermissionsResult(requestCode, permissions, grantResults)
}

Also it's necessary to delegate the response of 'ònActivityResult`to your LocationManager instance

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        locationManager.onActivityResult(requestCode, resultCode, data)
            ?: super.onActivityResult(requestCode, resultCode, data)
}

Get last known Location

Try to get last known connection with getLastKnownLocation.

locationManager.getLastKnownLocation(activity = this).observe(
      this,
      Observer<Location?> { location ->
          // handle location data
      })

Track location

If you want continuous information about device movement start the location tracking.

Start location tracking

To start location tracking call startLocationTracker.

locationManager.startLocationTracker(
    activity = this, config = LocationTrackerConfig()
).observe(
    this,
    Observer<Location?> { location ->
        // handle location data
    })

Stop location tracking

To stop location tracking call stopLocationTracker. This should be done at LifeCycleEvent onDestroy at least to avoid any error during off screen information.

locationManager.stopLocationTracker()

Customization

If the Permission is granted but the location provider is disabled a AlertDialog is shown. The options are 'Cancel' and 'Settings' to enable the Location Service again.

For customizing the text that is shown at the AlertDialog the following string resources must be overridden at you app:

  • R.string.locationmanager_gps_network_not_enabled (default: "Location Provider is not enabled. This Service is required otherwise no results will be posted.")
  • R.string.locationmanager_open_location_settings (default: "Settings")
  • R.string.locationmanager_btn_cancel (default: "Cancel")

Dependencies

Package Version
com.google.android.gms:play-services-location 15.0.1

Need Help or something missing?

Please submit an issue on GitHub.

License

This project is licensed under the terms of the MIT license. See the LICENSE file.

Build Environment

  Android Studio 4.0.1
  Build #AI-193.6911.18.40.6626763, built on June 25, 2020
  Runtime version: 1.8.0_242-release-1644-b3-6222593 x86_64
  VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
  macOS 10.15.5
You might also like...
🔓 Kotlin version of the popular google/easypermissions wrapper library to simplify basic system permissions logic on Android M or higher.
🔓 Kotlin version of the popular google/easypermissions wrapper library to simplify basic system permissions logic on Android M or higher.

EasyPermissions-ktx Kotlin version of the popular googlesample/easypermissions wrapper library to simplify basic system permissions logic on Android M

Android L Ripple effect wrapper for Views
Android L Ripple effect wrapper for Views

Material Ripple Layout Ripple effect wrapper for Android Views Including in your project compile 'com.balysv:material-ripple:1.0.2' Check for latest v

Android Java wrapper around ffmpeg command line binary

FFMPEG Library for Android This project is a Java wrapper around an ffmpeg command line binary for use in Android applications. It depends on the andr

A wrapper around Android's SQLiteDatabase with restoring capability

Restorable SQLiteDatabase RestorableSQLiteDatabase is a wrapper to replicate android's SQLiteDatabase class with restoring capability. This wrapper ma

Android WebView wrapper based on chromium

ChromiumWebView Android WebView wrapper based on chromium Notice This is just a experimental project, don't use it in product. If you have problem whe

Simple Android SharedPreferences wrapper.

Prefs Simple Android SharedPreferences wrapper. Repository Add this in your root build.gradle file (not your module build.gradle file): allprojects {

Wrapper around the android Camera class that simplifies its usage

EasyCamera Wrapper around the android Camera class that simplifies its usage (read more about the process) Usage: // the surface where the preview wil

Very easy to use wrapper library for Android SharePreferences

Treasure English document Treasure是一个Android平台上基于SharePreferences的偏好存储库,只需要定义接口,无需编写实现,默认支持Serializable和Parcelable。运行时0反射,不仅使用方便而且性能和原生写法几乎无差别。 使用方法 1

Android AsyncTask wrapper library, written in Kotlin

KillerTask This is a Kotlin Android library to create async background tasks. Inspired by TinyTask, but more beautiful and easy to use for Kotlin Andr

Repository for android animations Rx wrapper

RxAnimations RxAnimations is a library with the main goal to make android animations more solid and cohesive. Download compile 'oxim.digital:rxanim:

ResOf is an android resource wrapper library.

An android resource wrapper library.

A lightweight Kotlin friendly wrapper around Couchbase lite for Android.

CouchBaseKtx 🚧 Work In-Progress 🚧 A lightweight Kotlin friendly wrapper around Couchbase-lite for Android Read up a little bit of documentation abou

🔓 Kotlin version of the popular google/easypermissions wrapper library to simplify basic system permissions logic on Android M or higher.
🔓 Kotlin version of the popular google/easypermissions wrapper library to simplify basic system permissions logic on Android M or higher.

🔓 Kotlin version of the popular google/easypermissions wrapper library to simplify basic system permissions logic on Android M or higher.

This library is a set of simple wrapper classes that are aimed to help you easily access android device information.
This library is a set of simple wrapper classes that are aimed to help you easily access android device information.

SysInfo Simple, single class wrapper to get device information from an android device. This library provides an easy way to access all the device info

The Android wrapper of FlipClock.

FlipClock Android The Android wrapper for FlipClock. WHY? Fliqlo, the closed-source app for macOS has an iOS version, so I tried to make an Android ve

Wrapper of FusedLocationProviderClient for Android to support modern usage like LiveData and Flow

FancyLocationProvider Wrapper of FusedLocationProviderClient for Android to support modern usage like LiveData or Flow. Install Add Jitpack repository

🪁 Android Resources Wrapper Library
🪁 Android Resources Wrapper Library

Kite Android Resource Wrapper Library. TLDR Fed up with typing ContextCompat, resources and context all over your apps to access your resources? Say n

Cache wrapper for standart android VideoView

Android VideoView cache Cache wrapper for standart android VideoView It uses okhttp and rxjava inside. Nothing special is needed to use. Setup: Add ma

React Native wrapper to bridge our iOS and Android SDK
React Native wrapper to bridge our iOS and Android SDK

React Native wrapper to bridge our iOS and Android SDK

Owner
Thomas Cirksena
Passionate android developer since Android 1.5 ..... and still happy with it ;)
Thomas Cirksena
Countly Product Analytics Android SDK

Countly Android SDK We're hiring: Countly is looking for Android SDK developers, full stack devs, devops and growth hackers (remote work). Click this

Countly Team 648 Dec 23, 2022
CleverTap Android SDK

CleverTap Android SDKs ?? Introduction (Back to top) The CleverTap Android SDK for Mobile Customer Engagement and Analytics solutions CleverTap brings

CleverTap 71 Dec 2, 2022
LocationManager Wrapper for Android

Locationmanager Locationmanager is a small wrapper for Location Tracker. Installation Add jitpackto your repositories in Project build.gradle : allpro

Thomas Cirksena 19 Jan 19, 2022
Location 是一个通过 Android 自带的 LocationManager 来实现的定位功能

Location Location 是一个通过 Android 自带的 LocationManager 来实现的定位功能。 之所以写这个库的主要原因还需要从下面的场景说起:在开发某个App的过程当中,可能有个需求需要用到定位功能,但是又不那么重要; 这个时候如果选择使用第三方的定位服务,需要先去申请

Jenly 13 Oct 18, 2022
Wynncraft API Wrapper - Simple wrapper to get Wynncraft Stats of a player or a guild and more in Java

WynncraftAPIWrapper Simple wrapper to get Wynncraft Stats of a player or a guild

byBackfish 3 Sep 27, 2022
Android Shared preference wrapper than encrypts the values of Shared Preferences. It's not bullet proof security but rather a quick win for incrementally making your android app more secure.

Secure-preferences - Deprecated Please use EncryptedSharedPreferences from androidx.security in preferenced to secure-preference. (There are no active

Scott Alexander-Bown 1.5k Dec 24, 2022
Android Studio project wrapper around the Elixir TodoApp Desktop app to run on Android including the Erlang runtime

TodoApp Android: An Android Sample App This Android Studio project wraps the Desktop Sample App to run on an Android phone. How to build & run Install

elixir-desktop 78 Dec 10, 2022
Wrapper around the android Camera class that simplifies its usage

EasyCamera Wrapper around the android Camera class that simplifies its usage (read more about the process) Usage: // the surface where the preview wil

Bozhidar Bozhanov 642 Nov 27, 2022
A wrapper around Android's SQLiteDatabase with restoring capability

Restorable SQLiteDatabase RestorableSQLiteDatabase is a wrapper to replicate android's SQLiteDatabase class with restoring capability. This wrapper ma

Navid 21 Oct 21, 2022
Android L Ripple effect wrapper for Views

Material Ripple Layout Ripple effect wrapper for Android Views Including in your project compile 'com.balysv:material-ripple:1.0.2' Check for latest v

Balys Valentukevicius 2.3k Dec 29, 2022