Does anyone know how to provide your own LocationProvider and publish it to the system, so other apps may fetch a reference to it from the LocationManager?
For development and testing purposes you can implement a mock location provider. You need to enable "Allow mock locations" in developer options in order for applications to see locations from that provider.
For a code example, look at GPX Playback:
https://github.com/johncarpenter/Android-GPX-Mock-Location-Provider
The code for registering the location provider starts in line 203 of file
android/src/com/twolinessoftware/android/PlaybackService.java
.
If you want a "real" location provider (e.g. to deploy your functionality as part of an end-user application), some sources say it cannot be done unless that provider is in a package signed with the system key, so you'd have to build your own ROM from source, sign it with your key, sign your location provider with the same key and install both on your phone.
However, Android at some point introduced "unbundled" location providers. Apparently they needed that in order to move their own NetworkLocationProvider from the Android core into the Google Apps package.
I haven't seen an unbundled location provider working in practice yet and I'm not aware of any open-source code using it, but it looks like recent version of Android have support for "aftermarket" location providers.
Source code for the respective library is at
https://github.com/CyanogenMod/android_frameworks_base/tree/cm-10.1/location/lib
A location provider would have to extend com.android.location.provider.LocationProviderBase
.
Classes and methods are documented in the code.
Edit: Looking at
https://github.com/android/platform_frameworks_base/blob/master/core/res/AndroidManifest.xml
starting at line 607, it looks like the protection level for the INSTALL_LOCATION_PROVIDER
permission is signatureOrSystem
. This means that any app which uses this feature (i.e. installs a location provider, not necessarily the locaion provider itself) would either need to be signed with the same key as the platform (which would require you to build your entire Android system from source) or be installed as a system application (which might work on rooted devices).
There is some code at
https://github.com/microg/NetworkLocation
which seems to implement a LocationProvider. I haven't looked at it in detail (yet) or built it, so I cannot say if it works and what is requierd for it. But maybe it provides some pointers.
It cannot be done.
The problem is that only OEMs are allowed to install a new location provider. A third-party developer cannot grant to his/her application the permission required to install a new location provider (android.permission.INSTALL_LOCATION_PROVIDER).
See the answer of Dianne Hackborn (Android framework engineer) in this thread:
https://groups.google.com/d/topic/android-developers/OvCcdvO6jZY/discussion
To install a new location provider, you should develop a whole new firmware (like http://www.cyanogenmod.com/ ), insert your new location provider in this firmware and install all of this stuff o the user's phone.
See this SO thread, as well: Why are these permissions being refused?
All of this because of security concerns.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With