Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop - kotlin, background and foreground service for location #2

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@
/build
/captures
.externalNativeBuild
.idea/caches/build_file_checksums.ser
.idea/codeStyles/Project.xml
.idea/gradle.xml
.idea/misc.xml
.idea/vcs.xml
.idea/assetWizardSettings.xml
151 changes: 151 additions & 0 deletions .idea/assetWizardSettings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 0 additions & 24 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 17 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@

### Note need to handle the background limit - https://developer.android.com/about/versions/oreo/background-location-limits.html

### background package-
- runs always ie. in background thread, even when activity destroyed

### foreground package-
- runs foreground service - till activity is running

### LocationUpdatesComponent.kt - get the location
## WHAT [Get continuous location in android using background Service]
App module - API - LocationUpdatesService.java - min API - Android 5.0 21 LOLLIPOP - since job service arises in this api
GpsTracker module - min API 15
FusedLocationProviderClient.java - google client

#### DESCRIPTION
#### Permissions-
ACCESS_COARSE_LOCATION
ACCESS_FINE_LOCATION
#### Why JobScheduler
JobScheduler is guaranteed to get your job done, but since it operates at the system level.
https://medium.com/google-developers/scheduling-jobs-like-a-pro-with-jobscheduler-286ef8510129
JobScheduler is becoming the go-to answer for performing background work in Android. Android Nougat introduced several background optimizations,
for which JobScheduler is the best practice solution. So, if you haven’t already, it’s time to jump on the JobScheduler train.
FOREGROUND_SERVICE

#### Why FusedLocationProviderClient
Google’s Fused Location Services API
Most recommended API by everyone. The android official document recommends to use this way
Expand Down Expand Up @@ -39,9 +44,13 @@ Even when using the correct FusedLocationApi, there are a lot of things that can
users current location can be shown on google map



##### References
https://developer.android.com/training/location/receive-location-updates.html
https://github.com/googlesamples/android-play-location
https://github.com/codepath/android_guides/wiki/Retrieving-Location-with-LocationServices-API

#### TODO
- for android 10 handling is remaining...
If your app targets Android 10 or higher, you must declare the ACCESS_BACKGROUND_LOCATION permission in your app's manifest file and receive user permission in order to receive regular location updates while your app is in the background.
https://developer.android.com/training/location/receive-location-updates.html

16 changes: 9 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 27
compileSdkVersion 29
defaultConfig {
applicationId "dpm.location.tracker"
minSdkVersion 21
targetSdkVersion 27
targetSdkVersion 29
versionCode 1
versionName "1.0"
}
Expand All @@ -23,9 +23,11 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.0.2'
implementation 'com.android.support:design:27.0.2'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.google.android.gms:play-services-location:11.8.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.android.gms:play-services-location:17.0.0'

implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
}
22 changes: 14 additions & 8 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@

<uses-permission android:name="android.permission.INTERNET" />

<!--for location information-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

<!--foreground service-->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand All @@ -15,21 +19,23 @@
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".JobServiceDemoActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar">
android:name=".foreground.ForegroundServiceActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<service
android:name=".LocationUpdatesService"
android:label="My Job Service Update "
android:permission="android.permission.BIND_JOB_SERVICE" />
<activity
android:name=".background.BackgroundLocationActivity"
android:label="Background Service Demo" />

<service android:name=".foreground.ForegroundService" />

<service android:name=".background.BackgroundService" />

</application>

</manifest>
Binary file added app/src/main/ic_launcher-web.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading