Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/microg/android_external_unifiednlpapi
API interfaces and helpers to create backends for UnifiedNlp
https://github.com/microg/android_external_unifiednlpapi
android android-library api geocoder geocoding geolocation java microg unifiednlp
Last synced: 7 days ago
JSON representation
API interfaces and helpers to create backends for UnifiedNlp
- Host: GitHub
- URL: https://github.com/microg/android_external_unifiednlpapi
- Owner: microg
- License: apache-2.0
- Created: 2015-01-01T15:25:13.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2019-11-26T13:56:20.000Z (almost 5 years ago)
- Last Synced: 2024-09-21T09:11:12.067Z (about 2 months ago)
- Topics: android, android-library, api, geocoder, geocoding, geolocation, java, microg, unifiednlp
- Language: Java
- Homepage:
- Size: 140 KB
- Stars: 48
- Watchers: 21
- Forks: 37
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
UnifiedNlpApi
=============
This library contains anything needed to build a backend for UnifiedNlp.Writing the service
-------------------
### The easy way (Location)
Writing a service is fairly easy. Just create a class that extends `org.microg.nlp.api.LocationBackendService`, it provides several methods:#### `update()`-method
You'll most likely want to override this method. It is called every time when an application requests a location.However, as this method is blocking, you should not do heavy I/O operations (like network) in it.
If your backend uses a remote provider for location retrieval, do requests in an additional thread and return null in `update()`.
On request success, use `report()` to send the new location to the requesting application.See JavaDoc for additional information.
#### `onOpen()`-method and `onClose()`-method
These might be interesting to override too. `onOpen()` is called after UnifiedNlp connected to this backend and `onClose()` is called before connection closure.
This is a good place to initialize or respectively destroy whatever you need during `update()` calls.#### `report(Location)`-method
You can call this method every time to report the given location as soon as possible.### The easy way (Geocoding)
Providing a Geocoder is even simpler than a LocationProvider. Extend `org.microg.nlp.api.GeocoderBackendService` and implement the methods `getFromLocation` and `getFromLocationName`.
Both methods reflect a call to the corresponding method in `android.location.Geocoder`.### The flexible way
Instead of using the `LocationBackendService` helper class you can do it by hand.
It's important that your service overrides the `onBind()` method and responds with a `Binder` to the `LocationBackend` interface.Advertise your service
----------------------
To let UnifiedNlp see your service you need to advertise it by providing the `org.microg.nlp.LOCATION_BACKEND` action.For security reasons, you should add an `android:permission` restriction to `android.permission.ACCESS_COARSE_LOCATION`. This ensures only application with access to coarse locations will be able to connect to your service.
You may want to set `android:icon` and `android:label` to something reasonable, else your applications icon/label are used.
If your backend has settings you can advertise it's activity using the `org.microg.nlp.BACKEND_SETTINGS_ACTIVITY` meta-data so that it is callable from the UnifiedNlp settings.A service entry for a backend service could be: