location-samples | Multiple samples showing the best practices | Android library
kandi X-RAY | location-samples Summary
kandi X-RAY | location-samples Summary
The [location and context APIs] harness the sensors and signals of mobile devices to provide awareness of user actions and their environment, enabling delightful and engaging experiences that simplify user interactions, provide assistance, and help users to better understand themselves.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Called when a permission has been received
- Constructs a geofencingRequest
- Attempts to perform a pending geofencing task
- Adds a new geofences
- Handler for removing geofences
- Removes a geofences from the server
- Gets a PendingIntent that will be used to send a request to the LocationService
- Request permission
- Create the initial state
- Makes sure that the button is enabled
- Returns whether the geospences are added
- Generate a geofence list
- Handle a geofencing event
- Returns a string representation of the transition details
- Returns the error string corresponding to a geofence error code
- Sends a notification
- Handles adding geofences
- Updates whether or not the geospences are added
- Invoked when a geofence application is received
- Enqueue work in place
- Handler to add a new geofences button
- Called when the server starts
location-samples Key Features
location-samples Examples and Code Snippets
Community Discussions
Trending Discussions on location-samples
QUESTION
I am trying to write an app that tracks location in background and sends data to a server -- to monitor where my family members are, for example.
Currently I am playing with https://github.com/android/location-samples, particularly with LocationUpdatesBackgroundKotlin that seems to be the best way to receive location updates, but
after receiving about 8-10 location updates in background, the gps icon on the status bar dies without anyway notifying the application (here is the android/phone info, but I want the app to be compatible to Android 5.1).
I want to somehow know is receiving location updates alive or not and re-start it if it's dead (restarting receiving updates with fusedLocationClient.requestLocationUpdates
on line 105 of MyLocationManager
helps receiving further updates, but I have to monitor the status by eye).
Is there any way out, or a more reliable approach? Thanks.
P.S. Have been writing for android for a week.
ANSWER
Answered 2020-Oct-09 at 10:46In order to get location constantly from the application, you have to use the foreground service in which you can initialize the location manager and get the location update constantly as per the parameters that have been set. Also, make sure you have background location permission given as it is the requirement after API level 29. Following is the very basic flow of how it can be achieved. Make sure to start this service after taking the location permission:
QUESTION
I' trying to implement Google's android foreground location sample from github in my application. It works fine in the first run of the application. It requests for location permission and when the user grants permission, the service is starting flawlessly and fetches location.
But when the app runs the next time while it already has the permission, it crashes by showing a NullPointerException. I'm not able to narrow down the problem. What is different in the second run of the app which already has the permission? Getting error in OnStart()
in mService.requestLocationUpdates();
line.
Does it has to do anything with the package name that is declared in the LocationUpdatesService? or is it something else with permission? or with binding?
Stacktrace
...ANSWER
Answered 2020-Oct-21 at 12:58I am not sure, but try this:
QUESTION
I'm not sure what the behaviour should be in this case.
In the documentation it says that:
An app is considered to be accessing location in the background unless one of the following conditions is satisfied:
- An activity belonging to the app is visible.
- The app is running a foreground service that has declared a foreground service type of location.
In the example provided by google, they use an Activity which starts a foreground service in the foreground:
https://github.com/android/location-samples/tree/master/LocationUpdatesForegroundService
In my case, I need to start tracking locations once a bluetooth device is connected to my device (Using a manifest-registered broadcast receiver) - which could be in the background, or after the app terminated).
So, I'm declaring the service in the manifest like they say:
...ANSWER
Answered 2019-Dec-29 at 22:46On API 29, if you have an android:foregroundServiceType
of "location"
, you do not need ACCESS_BACKGROUND_LOCATION
. Any location access made while that Service
is running is considered a "foreground access".
But that assumes you can get the foreground service running. You must be continuing a user-initiated action of some sort. If the Service
is already running, then it won't be a problem; the Service
represents the continuation of a user-initiated action. If you need to start it when the BT device connects, well, I'm not sure if that qualifies. That may not work. (If you find out... please suggest an edit!)
An example of an app that needs the ACCESS_BACKGROUND_LOCATION
permission would be one that monitors your GPS position while no Activities
are visible, and no "location"
-type foreground service notifications are showing. On Android Q, this wouldn't be allowed to carry on for very long (more than about 30 seconds), without the permission.
I believe the OS also assigns ACCESS_BACKGROUND_LOCATION
to legacy apps where the user has elected to "Allow all the time" on the location permission dialog.
QUESTION
I'm trying to adapt Google's LocationsUpdatesForegroundService example into Kotlin to use in my app. Now, everything is going fine, until I need to make a reference to a service equal to null. That doesn't 'cause any problems within the Java code it originates from but, when I try to implement it in Kotlin, even if use null!!, I get a KotlinNullPointerException when I try to run the app and the app crashes. I'm not quite sure how to avoid this or set it in a different way. I've spent a few hours on this and sometime browsing StackOverFlow without really being able to find a solution for it. If anyone could help me, it'd be greatly appreciated. I've enclosed the link to the code I'm going off of here:
...as well as the necessary code I'm using below.
Relevant code from my Main Activity:
...ANSWER
Answered 2019-Nov-01 at 08:53You declare lservice
as:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install location-samples
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page