Courtesy: GitHub
Warning: file_get_contents(../git/googlesamples/android-play-location/LocationUpdatesForegroundService/README.md): failed to open stream: No such file or directory in /var/www/appsrox.com/public_html/ide/content.php on line 10

compileSdkVersion 25

applicationId "com.google.android.gms.location.sample.locationupdatesforegroundservice"

minSdkVersion 16

targetSdkVersion 25

versionCode 1

versionName "1.0"

compile fileTree(dir: 'libs', include: ['*.jar'])

compile 'com.android.support:appcompat-v7:25.3.1'

testCompile 'junit:junit:4.12'

compile 'com.google.android.gms:play-services-location:11.0.0'

compile 'com.android.support:design:25.3.1'

package com.google.android.gms.location.sample.locationupdatesforegroundservice

uses-permission

  • android.permission.ACCESS_FINE_LOCATION

MainActivity

Copyright 2017 Google Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

The only activity in this sample. Note: for apps running in the background on "O" devices (regardless of the targetSdkVersion), location may be computed less frequently than requested when the app is not in the foreground. Apps that use a foreground service - which involves displaying a non-dismissable notification - can bypass the background location limits and request location updates as before. This sample uses a long-running bound and started service for location updates. The service is aware of foreground status of this activity, which is the only bound client in this sample. After requesting location updates, when the activity ceases to be in the foreground, the service promotes itself to a foreground service and continues receiving location updates. When the activity comes back to the foreground, the foreground service stops, and the notification associated with that foreground service is removed. * While the foreground service notification is displayed, the user has the option to launch the activity from the notification. The user can also remove location updates directly from the notification. This dismisses the notification and stops the service.

Returns the current state of the permissions needed.

Callback received when a permissions request has been completed.

Receiver for broadcasts sent by {@link LocationUpdatesService}.

LocationUpdatesService

Copyright 2017 Google Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

A bound and started service that is promoted to a foreground service when location updates have been requested and all clients unbind. For apps running in the background on "O" devices, location is computed only once every 10 minutes and delivered batched every 30 minutes. This restriction applies even to apps targeting "N" or lower which are run on "O" devices. This sample show how to use a long-running service for location updates. When an activity is bound to this service, frequent location updates are permitted. When the activity is removed from the foreground, the service promotes itself to a foreground service, and location updates continue. When the activity comes back to the foreground, the foreground service stops, and the notification assocaited with that service is removed.

The desired interval for location updates. Inexact. Updates may be more or less frequent.

The fastest rate for active location updates. Updates will never be more frequent than this value.

The identifier for the notification displayed for the foreground service.

Used to check whether the bound activity has really gone away and not unbound as part of an orientation change. We create a foreground service notification only if the former takes place.

Contains parameters used by {@link com.google.android.gms.location.FusedLocationProviderApi}.

Provides access to the Fused Location Provider API.

Callback for changes in location.

The current location.

Makes a request for location updates. Note that in this sample we merely log the {@link SecurityException}.

Removes location updates. Note that in this sample we merely log the {@link SecurityException}.

Returns the {@link NotificationCompat} used as part of the foreground service.

Sets the location request parameters.

Class used for the client Binder. Since this service runs in the same process as its clients, we don't need to deal with IPC.

Returns true if this is a foreground service. * @param context The {@link Context}.