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...
Make Android screenshots of scrollable screen content
Make Android screenshots of scrollable screen content

scrollscreenshot Make Android screenshots of scrollable screen content - brought to you by PGS Software SA This tool makes a number of screenshots, sc

🍼Debug Bottle is an Android runtime debug / develop tools written using kotlin language.
🍼Debug Bottle is an Android runtime debug / develop tools written using kotlin language.

🇨🇳 中文 / 🇯🇵 日本語 / 🇬🇧 English 🍼 Debug Bottle An Android debug / develop tools written using Kotlin language. All the features in Debug bottle are

[] Dissect layout traversals on Android
[] Dissect layout traversals on Android

Probe Dissect layout traversals on Android. Features Intercept View methods. onMeasure(int, int) onLayout(boolean, int, int, int, int) draw(Canvas) an

Android Library Finder
Android Library Finder

alfi Android Library Finder Search through thousands of android libraries that can help you scale your projects elegantly Usage Search for something a

Annotation based simple API flavored with AOP to handle new Android runtime permission model

Let Annotation based simple API flavoured with AOP to handle new Android runtime permission model. If you check Google's Samples about the new permiss

Combines tools for fast android app devlopment

Android - Rapid Test Driven Development Combine tools to generate most of the boilerplate code. Examples how to test different aspects of an android a

Make mosaic effect on android
Make mosaic effect on android

ProMosaic Make mosaic for image on android. Features Select Mode Follow finger Select rectangle Effect Mode Grid color based on original image Blur Im

A set of Android tools that facilitate apps development
A set of Android tools that facilitate apps development

A set of Android tools that facilitate apps development Well, this repo contains pretty much code used internally at Stanfy to develop Android apps. S

A multi platform image density converting tool converting single or batches of images to Android, iOS, Windows or CSS specific formats and density versions given the source scale factor or width/height in dp. It has a graphical and command line interface and supports many image types (svg, psd, 9-patch, etc.) aswell as some lossless compressors like pngcrush.
Owner
Thomas Cirksena
Passionate android developer since Android 1.5 ..... and still happy with it ;)
Thomas Cirksena
A tool to install components of the Android SDK into a Maven repository or repository manager to use with the Android Maven Plugin, Gradle and other tools.

Maven Android SDK Deployer Original author including numerous fixes and changes: Manfred Moser [email protected] at simpligility technologies i

simpligility 1.4k Dec 27, 2022
A simple utility to remove unused resources in your Android app to lower the size of the APK. It's based on the Android lint tool output.

android-resource-remover android-resource-remover is utility that removes unused resources reported by Android Lint from your project. The goal is to

Keepsafe 1.3k Dec 16, 2022
This is a Android Studio/ IntelliJ IDEA plugin to localize your Android app, translate your string resources automactically.

#Android Localizationer This is a Android Studio/ IntelliJ IDEA plugin to localize your Android app, translate your string resources automactically. T

Wesley Lin 822 Dec 8, 2022
A tool to install components of the Android SDK into a Maven repository or repository manager to use with the Android Maven Plugin, Gradle and other tools.

Maven Android SDK Deployer Original author including numerous fixes and changes: Manfred Moser [email protected] at simpligility technologies i

simpligility 1.4k Dec 27, 2022
Automated-build-android-app-with-github-action - CI/CD Automated Build Android App Bundle / APK / Signed With Github Action

Automated Build Android With Using Github Action Project Github Action Script Us

Faisal Amir 34 Dec 19, 2022
proguard resource for Android by wechat team

AndResGuard Read this in other languages: English, 简体中文. AndResGuard is a tooling for reducing your apk size, it works like the ProGuard for Java sour

shwenzhang 8.1k Jan 9, 2023
A super fast build tool for Android, an alternative to Instant Run

Freeline Freeline is a super fast build tool for Android and an alternative to Instant Run. Caching reusable class files and resource indices, it enab

Alibaba 5.5k Jan 2, 2023
Command-line tool to count per-package methods in Android .dex files

dex-method-counts Simple tool to output per-package method counts in an Android DEX executable grouped by package, to aid in getting under the 65,536

Mihai Parparita 2.6k Nov 25, 2022
View Inspection Toolbar for Android Development

View Inspector Plugin View inspection toolbar for android development. Features Boundary show outlines show margins show paddings Layer Scalpel featur

Fumihiro Xue (Peter Hsieh) 2.2k Nov 14, 2022