Bootstrap your location-aware Android app with LocationFetcher: a simple and effective library
Android Location API can be complicated and scary for beginners.
As an Android developer, I've developed a few location-based apps and have learned (the hard way) much about Android location APIs. With the knowledge I've gathered, I've developed a library to help you bootstrap your own location-based apps, abstracting the API details and letting you focus on your real use-cases.
Imagine making your Android app with location-awareness being as simple as installing a library and observing location data and settings:
Installation
Using Gradle
On project-level build.gradle, add:
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
On app-level build.gradle, add:
implementation 'com.github.psteiger:locationfetcher:5.+'
On Manifest
On root level, allow permission:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Usage
On any FragmentActivity
or Context
class, you can instantiate a LocationFetcher
by calling:
LocationFetcher.create(this)
There are two LocationFetcher.create()
method signatures: LocationFetcher.create(Context)
and LocationFetcher.create(FragmentActivity)
If LocationFetcher
is created with a FragmentActivity
, it will be able to show dialogs to request the user to enable permission in Android settings and to allow the app to obtain the device's location. If LocationFetcher
is created with a non-FragmentActivity
Context
, it won't be able to show dialogs.
Once instantiated, the component gives you three Flow
s to collect: one for new locations, one for settings status, and one for location permissions status.
To manually request location permissions or location settings enablement, you can call the following APIs:
Custom configurations
You can optionally personalize configurations when instantiating LocationFetcher