├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── values
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── strings.xml
│ │ │ │ ├── drawables.xml
│ │ │ │ └── styles.xml
│ │ │ ├── values-v21
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── drawable
│ │ │ │ ├── side_nav_bar.xml
│ │ │ │ └── ic_launcher_background.xml
│ │ │ ├── drawable-v21
│ │ │ │ ├── ic_menu_send.xml
│ │ │ │ ├── ic_menu_slideshow.xml
│ │ │ │ ├── ic_menu_gallery.xml
│ │ │ │ ├── ic_menu_manage.xml
│ │ │ │ ├── ic_menu_camera.xml
│ │ │ │ └── ic_menu_share.xml
│ │ │ ├── menu
│ │ │ │ ├── job_service_demo.xml
│ │ │ │ └── activity_job_service_demo_drawer.xml
│ │ │ ├── layout
│ │ │ │ ├── activity_job_service_demo.xml
│ │ │ │ ├── app_bar_job_service_demo.xml
│ │ │ │ ├── nav_header_job_service_demo.xml
│ │ │ │ └── content_job_service_demo.xml
│ │ │ └── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── dpm
│ │ │ └── location
│ │ │ └── tracker
│ │ │ ├── Utils.java
│ │ │ ├── LocationUpdatesService.java
│ │ │ ├── LocationUpdatesComponent.java
│ │ │ └── JobServiceDemoActivity.java
│ └── test
│ │ └── java
│ │ └── dpm
│ │ └── location
│ │ └── tracker
│ │ └── ExampleUnitTest.kt
├── proguard-rules.pro
└── build.gradle
├── locationTrack
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ ├── layout
│ │ │ │ └── activity_main.xml
│ │ │ └── drawable
│ │ │ │ └── ic_launcher_background.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── app
│ │ │ └── prior
│ │ │ └── tracker
│ │ │ ├── MyIntentService.java
│ │ │ ├── MainActivity.java
│ │ │ └── LocationUpdatesComponent.java
│ ├── test
│ │ └── java
│ │ │ └── app
│ │ │ └── prior
│ │ │ └── tracker
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── app
│ │ └── prior
│ │ └── tracker
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── .idea
├── vcs.xml
├── modules.xml
├── runConfigurations.xml
├── gradle.xml
└── misc.xml
├── gradle.properties
├── README.md
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/locationTrack/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dinkar1708-zz/LocationTrackerAndroid/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/locationTrack/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Location Track
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dinkar1708-zz/LocationTrackerAndroid/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dinkar1708-zz/LocationTrackerAndroid/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dinkar1708-zz/LocationTrackerAndroid/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dinkar1708-zz/LocationTrackerAndroid/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dinkar1708-zz/LocationTrackerAndroid/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dinkar1708-zz/LocationTrackerAndroid/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dinkar1708-zz/LocationTrackerAndroid/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dinkar1708-zz/LocationTrackerAndroid/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dinkar1708-zz/LocationTrackerAndroid/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dinkar1708-zz/LocationTrackerAndroid/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/locationTrack/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dinkar1708-zz/LocationTrackerAndroid/HEAD/locationTrack/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/locationTrack/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dinkar1708-zz/LocationTrackerAndroid/HEAD/locationTrack/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/locationTrack/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dinkar1708-zz/LocationTrackerAndroid/HEAD/locationTrack/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/locationTrack/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dinkar1708-zz/LocationTrackerAndroid/HEAD/locationTrack/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/locationTrack/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dinkar1708-zz/LocationTrackerAndroid/HEAD/locationTrack/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/locationTrack/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dinkar1708-zz/LocationTrackerAndroid/HEAD/locationTrack/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/locationTrack/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dinkar1708-zz/LocationTrackerAndroid/HEAD/locationTrack/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/locationTrack/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dinkar1708-zz/LocationTrackerAndroid/HEAD/locationTrack/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/locationTrack/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dinkar1708-zz/LocationTrackerAndroid/HEAD/locationTrack/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/locationTrack/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dinkar1708-zz/LocationTrackerAndroid/HEAD/locationTrack/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/locationTrack/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Feb 16 17:20:06 IST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/locationTrack/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/locationTrack/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/side_nav_bar.xml:
--------------------------------------------------------------------------------
1 |
3 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v21/ic_menu_send.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 8dp
6 | 176dp
7 | 16dp
8 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/job_service_demo.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
--------------------------------------------------------------------------------
/locationTrack/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | LocationTrackerAndroid
3 |
4 | Open navigation drawer
5 | Close navigation drawer
6 |
7 | Settings
8 | Job Service Fused Location Provider Client
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/test/java/dpm/location/tracker/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package dpm.location.tracker
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v21/ic_menu_slideshow.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v21/ic_menu_gallery.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/locationTrack/src/test/java/app/prior/tracker/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package app.prior.tracker;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v21/ic_menu_manage.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values/drawables.xml:
--------------------------------------------------------------------------------
1 |
2 | - @android:drawable/ic_menu_camera
3 | - @android:drawable/ic_menu_gallery
4 | - @android:drawable/ic_menu_slideshow
5 | - @android:drawable/ic_menu_manage
6 | - @android:drawable/ic_menu_share
7 | - @android:drawable/ic_menu_send
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v21/ic_menu_camera.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v21/ic_menu_share.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/locationTrack/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/locationTrack/src/androidTest/java/app/prior/tracker/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package app.prior.tracker;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("app.prior.lollipop", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/locationTrack/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 27
5 |
6 |
7 |
8 | defaultConfig {
9 | applicationId "app.prior.lollipop"
10 | minSdkVersion 15
11 | targetSdkVersion 27
12 | versionCode 1
13 | versionName "1.0"
14 |
15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16 |
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 |
26 | }
27 |
28 | dependencies {
29 | implementation fileTree(dir: 'libs', include: ['*.jar'])
30 |
31 | implementation 'com.android.support:appcompat-v7:27.0.2'
32 | implementation 'com.android.support:design:27.0.2'
33 | implementation 'com.android.support.constraint:constraint-layout:1.0.2'
34 | implementation 'com.google.android.gms:play-services-location:11.8.0'
35 | }
36 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | apply plugin: 'kotlin-android'
4 |
5 | apply plugin: 'kotlin-android-extensions'
6 |
7 | android {
8 | compileSdkVersion 27
9 | defaultConfig {
10 | applicationId "dpm.location.tracker"
11 | minSdkVersion 21
12 | targetSdkVersion 27
13 | versionCode 1
14 | versionName "1.0"
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | dependencies {
25 | implementation fileTree(dir: 'libs', include: ['*.jar'])
26 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
27 | implementation 'com.android.support:appcompat-v7:27.0.2'
28 | implementation 'com.android.support:design:27.0.2'
29 | implementation 'com.android.support.constraint:constraint-layout:1.0.2'
30 | implementation 'com.google.android.gms:play-services-location:11.8.0'
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_job_service_demo.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
15 |
16 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/locationTrack/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/app_bar_job_service_demo.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/activity_job_service_demo_drawer.xml:
--------------------------------------------------------------------------------
1 |
2 |
39 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
17 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/nav_header_job_service_demo.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
21 |
22 |
28 |
29 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/content_job_service_demo.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
22 |
23 |
34 |
35 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/locationTrack/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/java/dpm/location/tracker/Utils.java:
--------------------------------------------------------------------------------
1 | package dpm.location.tracker;
2 |
3 | import android.app.job.JobInfo;
4 | import android.app.job.JobScheduler;
5 | import android.content.ComponentName;
6 | import android.content.Context;
7 | import android.location.Location;
8 | import android.location.LocationManager;
9 | import android.net.ConnectivityManager;
10 | import android.net.NetworkInfo;
11 | import android.preference.PreferenceManager;
12 | import android.util.Log;
13 |
14 | import java.text.DateFormat;
15 | import java.util.Date;
16 |
17 | import static android.content.Context.JOB_SCHEDULER_SERVICE;
18 |
19 | /**
20 | * utility class
21 | */
22 |
23 | public class Utils {
24 |
25 | private static final String TAG = Utils.class.getSimpleName();
26 |
27 | /**
28 | * schedule job once
29 | *
30 | * @param context
31 | * @param cls
32 | */
33 | public static void scheduleJob(Context context, Class> cls) {
34 | ComponentName serviceComponent = new ComponentName(context, cls);
35 |
36 | JobInfo.Builder builder = new JobInfo.Builder(0, serviceComponent);
37 | builder.setMinimumLatency(1 * 1000); // wait at least
38 | builder.setOverrideDeadline(3 * 1000); // maximum delay
39 | // builder.setPeriodic(5 * 1000);
40 | builder.setRequiresCharging(false); // we don't care if the device is charging or not
41 | JobScheduler jobScheduler = (JobScheduler) context.getSystemService(JOB_SCHEDULER_SERVICE);
42 |
43 | jobScheduler.schedule(builder.build());
44 | }
45 |
46 | /**
47 | * schedule job always in every 5 seconds, can be parametrized time - ie. pass time in parameter
48 | *
49 | * @param context
50 | * @param cls
51 | */
52 | public static void scheduleJob1(Context context, Class> cls) {
53 | ComponentName serviceComponent = new ComponentName(context, cls);
54 | JobInfo.Builder builder = new JobInfo.Builder(0, serviceComponent);
55 | builder.setPeriodic(5 * 1000);
56 | builder.setRequiresCharging(false); // we don't care if the device is charging or not
57 | JobScheduler jobScheduler = (JobScheduler) context.getSystemService(JOB_SCHEDULER_SERVICE);
58 | jobScheduler.schedule(builder.build());
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/locationTrack/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
24 |
25 |
36 |
37 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | ## WHAT [Get continuous location in android using background Service]
3 | App module - API - LocationUpdatesService.java - min API - Android 5.0 21 LOLLIPOP - since job service arises in this api
4 | GpsTracker module - min API 15
5 | FusedLocationProviderClient.java - google client
6 | #### DESCRIPTION
7 | #### Permissions-
8 | ACCESS_COARSE_LOCATION
9 | ACCESS_FINE_LOCATION
10 | #### Why JobScheduler
11 | JobScheduler is guaranteed to get your job done, but since it operates at the system level.
12 | https://medium.com/google-developers/scheduling-jobs-like-a-pro-with-jobscheduler-286ef8510129
13 | JobScheduler is becoming the go-to answer for performing background work in Android. Android Nougat introduced several background optimizations,
14 | for which JobScheduler is the best practice solution. So, if you haven’t already, it’s time to jump on the JobScheduler train.
15 | #### Why FusedLocationProviderClient
16 | Google’s Fused Location Services API
17 | Most recommended API by everyone. The android official document recommends to use this way
18 | FusedLocationProviderClient is inside LocationServices class and uses the feature
19 | ```
20 | mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
21 | ```
22 | https://github.com/codepath/android_guides/wiki/Retrieving-Location-with-LocationServices-API
23 | Location updates should always be done using the FusedLocationProviderClient leveraging the LocationServices.API as shown above.
24 | Do not use the older Location APIs which are much less reliable.
25 | Even when using the correct FusedLocationApi, there are a lot of things that can go wrong.
26 |
27 | ##### Why not use GoogleApiClient?
28 | Reference - https://android-developers.googleblog.com/2017/06/reduce-friction-with-new-location-apis.html
29 |
30 | #### OUTPUT
31 | Location continuously retrieved in service
32 | Location continuously sending on activity
33 |
34 | #### FUTURE SCOPE
35 | Gps tracker
36 | Location tracker
37 | Foot print tracking
38 | all above typs of application can be created
39 | users current location can be shown on google map
40 |
41 |
42 |
43 | ##### References
44 | https://developer.android.com/training/location/receive-location-updates.html
45 | https://github.com/googlesamples/android-play-location
46 | https://github.com/codepath/android_guides/wiki/Retrieving-Location-with-LocationServices-API
47 |
48 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/locationTrack/src/main/java/app/prior/tracker/MyIntentService.java:
--------------------------------------------------------------------------------
1 | package app.prior.tracker;
2 |
3 | import android.app.IntentService;
4 | import android.content.Intent;
5 | import android.location.Location;
6 | import android.os.Message;
7 | import android.os.Messenger;
8 | import android.os.RemoteException;
9 | import android.util.Log;
10 |
11 | import static app.prior.tracker.MainActivity.MESSENGER_INTENT_KEY;
12 |
13 | /**
14 | * An {@link IntentService} subclass for handling asynchronous task requests in
15 | * a service on a separate handler thread.
16 | *
17 | * helper methods.
18 | */
19 | public class MyIntentService extends IntentService implements LocationUpdatesComponent.ILocationProvider {
20 | private static final String TAG = MyIntentService.class.getSimpleName();
21 | public static final int LOCATION_MESSAGE = 999;
22 |
23 | private LocationUpdatesComponent locationUpdatesComponent;
24 | private Messenger mActivityMessenger;
25 |
26 | public MyIntentService() {
27 | super("MyIntentService");
28 | }
29 |
30 | @Override
31 | public void onCreate() {
32 | super.onCreate();
33 | Log.i(TAG, "onCreate ");
34 |
35 | locationUpdatesComponent = new LocationUpdatesComponent(this);
36 | locationUpdatesComponent.onCreate(this);
37 | }
38 |
39 | // this makes service running continuously,,commenting this start command method service runs only once
40 | @Override
41 | public int onStartCommand(Intent intent, int flags, int startId) {
42 | Log.i(TAG, "onStartCommand Service started....");
43 | if (intent != null) {
44 | mActivityMessenger = intent.getParcelableExtra(MESSENGER_INTENT_KEY);
45 | }
46 |
47 | //hey request for location updates
48 | locationUpdatesComponent.onStart();
49 | return START_STICKY;
50 | }
51 |
52 | @Override
53 | public void onDestroy() {
54 | super.onDestroy();
55 | Log.i(TAG, "onDestroy...");
56 |
57 | locationUpdatesComponent.onStop();
58 | }
59 |
60 | @Override
61 | protected void onHandleIntent(Intent intent) {
62 | Log.i(TAG, "onHandleIntent" + intent);
63 | if (intent != null) {
64 | final String action = intent.getAction();
65 | }
66 | }
67 |
68 | /**
69 | * send message by using messenger
70 | *
71 | * @param messageID
72 | */
73 | private void sendMessage(int messageID, Location location) {
74 | // If this service is launched by the JobScheduler, there's no callback Messenger. It
75 | // only exists when the MainActivity calls startService() with the callback in the Intent.
76 | if (mActivityMessenger == null) {
77 | Log.d(TAG, "Service is bound, not started. There's no callback to send a message to.");
78 | return;
79 | }
80 | Message m = Message.obtain();
81 | m.what = messageID;
82 | m.obj = location;
83 | try {
84 | mActivityMessenger.send(m);
85 | } catch (RemoteException e) {
86 | Log.e(TAG, "Error passing service object back to activity.");
87 | }
88 | }
89 |
90 | @Override
91 | public void onLocationUpdate(Location location) {
92 | sendMessage(LOCATION_MESSAGE, location);
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/app/src/main/java/dpm/location/tracker/LocationUpdatesService.java:
--------------------------------------------------------------------------------
1 | package dpm.location.tracker;
2 |
3 | import android.app.job.JobParameters;
4 | import android.app.job.JobService;
5 | import android.content.Intent;
6 | import android.content.res.Configuration;
7 | import android.location.Location;
8 | import android.os.Message;
9 | import android.os.Messenger;
10 | import android.os.RemoteException;
11 | import android.util.Log;
12 |
13 | import static dpm.location.tracker.JobServiceDemoActivity.MESSENGER_INTENT_KEY;
14 |
15 |
16 | /**
17 | * location update service continues to running and getting location information
18 | */
19 | public class LocationUpdatesService extends JobService implements LocationUpdatesComponent.ILocationProvider {
20 |
21 | private static final String TAG = LocationUpdatesService.class.getSimpleName();
22 | public static final int LOCATION_MESSAGE = 9999;
23 |
24 | private Messenger mActivityMessenger;
25 |
26 | private LocationUpdatesComponent locationUpdatesComponent;
27 |
28 | public LocationUpdatesService() {
29 | }
30 |
31 | @Override
32 | public boolean onStartJob(JobParameters params) {
33 | Log.i(TAG, "onStartJob....");
34 | // Utils.scheduleJob(getApplicationContext(), LocationUpdatesService.class);
35 | return true;
36 | }
37 |
38 | @Override
39 | public boolean onStopJob(JobParameters params) {
40 | Log.i(TAG, "onStopJob....");
41 |
42 | locationUpdatesComponent.onStop();
43 |
44 | return false;
45 | }
46 |
47 | @Override
48 | public void onCreate() {
49 | Log.i(TAG, "created...............");
50 |
51 | locationUpdatesComponent = new LocationUpdatesComponent(this);
52 |
53 | locationUpdatesComponent.onCreate(this);
54 | }
55 |
56 | @Override
57 | public int onStartCommand(Intent intent, int flags, int startId) {
58 | Log.i(TAG, "onStartCommand Service started");
59 | if (intent != null) {
60 | mActivityMessenger = intent.getParcelableExtra(MESSENGER_INTENT_KEY);
61 | }
62 | //hey request for location updates
63 | locationUpdatesComponent.onStart();
64 |
65 | /* HandlerThread handlerThread = new HandlerThread(TAG);
66 | handlerThread.start();
67 | mServiceHandler = new Handler(handlerThread.getLooper());*/
68 |
69 | //This thread is need to continue the service running
70 | /* new Thread(new Runnable() {
71 | @Override
72 | public void run() {
73 | for (; ; ) {
74 | Log.i(TAG, "thread... is running...");
75 | try {
76 | Thread.sleep(5 * 1000);
77 | } catch (InterruptedException e) {
78 | e.printStackTrace();
79 | }
80 | }
81 | }
82 | }).start();*/
83 |
84 | return START_STICKY;
85 | }
86 |
87 | @Override
88 | public void onConfigurationChanged(Configuration newConfig) {
89 | super.onConfigurationChanged(newConfig);
90 | }
91 |
92 | @Override
93 | public void onRebind(Intent intent) {
94 | // Called when a client (MainActivity in case of this sample) returns to the foreground
95 | // and binds once again with this service. The service should cease to be a foreground
96 | // service when that happens.
97 | Log.i(TAG, "in onRebind()");
98 | super.onRebind(intent);
99 | }
100 |
101 | @Override
102 | public boolean onUnbind(Intent intent) {
103 | Log.i(TAG, "Last client unbound from service");
104 |
105 | return true; // Ensures onRebind() is called when a client re-binds.
106 | }
107 |
108 | @Override
109 | public void onDestroy() {
110 | Log.i(TAG, "onDestroy....");
111 | }
112 |
113 | /**
114 | * send message by using messenger
115 | *
116 | * @param messageID
117 | */
118 | private void sendMessage(int messageID, Location location) {
119 | // If this service is launched by the JobScheduler, there's no callback Messenger. It
120 | // only exists when the MainActivity calls startService() with the callback in the Intent.
121 | if (mActivityMessenger == null) {
122 | Log.d(TAG, "Service is bound, not started. There's no callback to send a message to.");
123 | return;
124 | }
125 | Message m = Message.obtain();
126 | m.what = messageID;
127 | m.obj = location;
128 | try {
129 | mActivityMessenger.send(m);
130 | } catch (RemoteException e) {
131 | Log.e(TAG, "Error passing service object back to activity.");
132 | }
133 | }
134 |
135 | @Override
136 | public void onLocationUpdate(Location location) {
137 | sendMessage(LOCATION_MESSAGE, location);
138 | }
139 | }
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/locationTrack/src/main/java/app/prior/tracker/MainActivity.java:
--------------------------------------------------------------------------------
1 | package app.prior.tracker;
2 |
3 | import android.Manifest;
4 | import android.content.Intent;
5 | import android.content.pm.PackageManager;
6 | import android.location.Location;
7 | import android.os.Bundle;
8 | import android.os.Handler;
9 | import android.os.Message;
10 | import android.os.Messenger;
11 | import android.support.annotation.NonNull;
12 | import android.support.v4.app.ActivityCompat;
13 | import android.support.v7.app.AppCompatActivity;
14 | import android.util.Log;
15 | import android.view.View;
16 | import android.widget.TextView;
17 |
18 | import java.text.DateFormat;
19 | import java.util.Date;
20 |
21 | public class MainActivity extends AppCompatActivity {
22 |
23 | private static final String TAG = MainActivity.class.getSimpleName();
24 |
25 | private static final int REQUEST_PERMISSIONS_REQUEST_CODE = 34;
26 | public static final String MESSENGER_INTENT_KEY = "msg-intent-key";
27 |
28 | // as google doc says
29 | // Handler for incoming messages from the service.
30 | private IncomingMessageHandler mHandler;
31 | private TextView locationMsg;
32 |
33 | @Override
34 | protected void onCreate(Bundle savedInstanceState) {
35 | super.onCreate(savedInstanceState);
36 | setContentView(R.layout.activity_main);
37 |
38 | locationMsg = findViewById(R.id.location);
39 |
40 | findViewById(R.id.start).setOnClickListener(new View.OnClickListener() {
41 | @Override
42 | public void onClick(View v) {
43 | requestPermissions();
44 |
45 | }
46 | });
47 |
48 | findViewById(R.id.stop).setOnClickListener(new View.OnClickListener() {
49 | @Override
50 | public void onClick(View v) {
51 | stopService(new Intent(MainActivity.this, MyIntentService.class));
52 | }
53 | });
54 |
55 | mHandler = new IncomingMessageHandler();
56 |
57 | }
58 |
59 | private void requestPermissions() {
60 | boolean shouldProvideRationale =
61 | ActivityCompat.shouldShowRequestPermissionRationale(this,
62 | Manifest.permission.ACCESS_FINE_LOCATION);
63 |
64 | // Provide an additional rationale to the user. This would happen if the user denied the
65 | // request previously, but didn't check the "Don't ask again" checkbox.
66 | if (shouldProvideRationale) {
67 | Log.i(TAG, "Displaying permission rationale to provide additional context.");
68 | // Request permission
69 | ActivityCompat.requestPermissions(this,
70 | new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
71 | REQUEST_PERMISSIONS_REQUEST_CODE);
72 | } else {
73 | Log.i(TAG, "Requesting permission");
74 | // Request permission. It's possible this can be auto answered if device policy
75 | // sets the permission in a given state or the user denied the permission
76 | // previously and checked "Never ask again".
77 | ActivityCompat.requestPermissions(this,
78 | new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
79 | REQUEST_PERMISSIONS_REQUEST_CODE);
80 | }
81 | }
82 |
83 | /**
84 | * Callback received when a permissions request has been completed.
85 | */
86 | @Override
87 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
88 | @NonNull int[] grantResults) {
89 | Log.i(TAG, "onRequestPermissionResult grantResults " + grantResults);
90 | if (requestCode == REQUEST_PERMISSIONS_REQUEST_CODE) {
91 | if (grantResults.length <= 0) {
92 | // If user interaction was interrupted, the permission request is cancelled and you
93 | // receive empty arrays.
94 | Log.i(TAG, "User interaction was cancelled.");
95 | finish();
96 | } else if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
97 | // can be schedule in this way also
98 | // Utils.scheduleJob(this, LocationUpdatesService.class);
99 | //doing this way to communicate via messenger
100 | // Start service and provide it a way to communicate with this class.
101 | Intent startServiceIntent = new Intent(this, MyIntentService.class);
102 | Messenger messengerIncoming = new Messenger(mHandler);
103 | startServiceIntent.putExtra(MESSENGER_INTENT_KEY, messengerIncoming);
104 | startService(startServiceIntent);
105 | } else {
106 | // Permission denied.
107 | finish();
108 | }
109 | }
110 | }
111 |
112 | class IncomingMessageHandler extends Handler {
113 | @Override
114 | public void handleMessage(Message msg) {
115 | Log.i(TAG, "handleMessage..." + msg.toString());
116 |
117 | super.handleMessage(msg);
118 |
119 | switch (msg.what) {
120 | case MyIntentService.LOCATION_MESSAGE:
121 | Location obj = (Location) msg.obj;
122 | String currentDateTimeString = DateFormat.getDateTimeInstance().format(new Date());
123 | locationMsg.setText("LAT : " + obj.getLatitude() + "\nLNG : " + obj.getLongitude() + "\n\n" + obj.toString() + " \n\n\nLast updated- " + currentDateTimeString);
124 | break;
125 | }
126 | }
127 | }
128 |
129 |
130 | }
131 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/locationTrack/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/java/dpm/location/tracker/LocationUpdatesComponent.java:
--------------------------------------------------------------------------------
1 | package dpm.location.tracker;
2 |
3 | import android.content.Context;
4 | import android.location.Location;
5 | import android.os.Looper;
6 | import android.support.annotation.NonNull;
7 | import android.util.Log;
8 |
9 | import com.google.android.gms.location.FusedLocationProviderClient;
10 | import com.google.android.gms.location.LocationCallback;
11 | import com.google.android.gms.location.LocationRequest;
12 | import com.google.android.gms.location.LocationResult;
13 | import com.google.android.gms.location.LocationServices;
14 | import com.google.android.gms.tasks.OnCompleteListener;
15 | import com.google.android.gms.tasks.Task;
16 |
17 |
18 | /**
19 | * stand alone component for location updates
20 | */
21 | public class LocationUpdatesComponent {
22 |
23 | private static final String TAG = LocationUpdatesComponent.class.getSimpleName();
24 |
25 | /**
26 | * The desired interval for location updates. Inexact. Updates may be more or less frequent.
27 | */
28 | private static final long UPDATE_INTERVAL_IN_MILLISECONDS = 3 * 1000;
29 |
30 | /**
31 | * The fastest rate for active location updates. Updates will never be more frequent
32 | * than this value.
33 | */
34 | private static final long FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS =
35 | UPDATE_INTERVAL_IN_MILLISECONDS / 2;
36 |
37 | private LocationRequest mLocationRequest;
38 |
39 | /**
40 | * Provides access to the Fused Location Provider API.
41 | */
42 | private FusedLocationProviderClient mFusedLocationClient;
43 |
44 | /**
45 | * Callback for changes in location.
46 | */
47 | private LocationCallback mLocationCallback;
48 |
49 | /**
50 | * The current location.
51 | */
52 | private Location mLocation;
53 |
54 | public ILocationProvider iLocationProvider;
55 |
56 | public LocationUpdatesComponent(ILocationProvider iLocationProvider) {
57 | this.iLocationProvider = iLocationProvider;
58 | }
59 |
60 | /**
61 | * create first time to initialize the location components
62 | *
63 | * @param context
64 | */
65 | public void onCreate(Context context) {
66 | Log.i(TAG, "created...............");
67 | mFusedLocationClient = LocationServices.getFusedLocationProviderClient(context);
68 |
69 | mLocationCallback = new LocationCallback() {
70 | @Override
71 | public void onLocationResult(LocationResult locationResult) {
72 | super.onLocationResult(locationResult);
73 | Log.i(TAG, "onCreate...onLocationResult...............loc " + locationResult.getLastLocation());
74 |
75 | onNewLocation(locationResult.getLastLocation());
76 | }
77 | };
78 | // create location request
79 | createLocationRequest();
80 | // get last known location
81 | getLastLocation();
82 | }
83 |
84 | /**
85 | * start location updates
86 | */
87 | public void onStart() {
88 | Log.i(TAG, "onStart ");
89 | //hey request for location updates
90 | requestLocationUpdates();
91 | }
92 |
93 | /**
94 | * remove location updates
95 | */
96 | public void onStop() {
97 | Log.i(TAG, "onStop....");
98 | removeLocationUpdates();
99 | }
100 |
101 | /**
102 | * Makes a request for location updates. Note that in this sample we merely log the
103 | * {@link SecurityException}.
104 | */
105 | public void requestLocationUpdates() {
106 | Log.i(TAG, "Requesting location updates");
107 | try {
108 | mFusedLocationClient.requestLocationUpdates(mLocationRequest,
109 | mLocationCallback, Looper.getMainLooper());
110 | } catch (SecurityException unlikely) {
111 | Log.e(TAG, "Lost location permission. Could not request updates. " + unlikely);
112 | }
113 | }
114 |
115 | /**
116 | * Removes location updates. Note that in this sample we merely log the
117 | * {@link SecurityException}.
118 | */
119 | public void removeLocationUpdates() {
120 | Log.i(TAG, "Removing location updates");
121 | try {
122 | mFusedLocationClient.removeLocationUpdates(mLocationCallback);
123 | // Utils.setRequestingLocationUpdates(this, false);
124 | // stopSelf();
125 | } catch (SecurityException unlikely) {
126 | // Utils.setRequestingLocationUpdates(this, true);
127 | Log.e(TAG, "Lost location permission. Could not remove updates. " + unlikely);
128 | }
129 | }
130 |
131 | /**
132 | * get last location
133 | */
134 | private void getLastLocation() {
135 | try {
136 | mFusedLocationClient.getLastLocation()
137 | .addOnCompleteListener(new OnCompleteListener() {
138 | @Override
139 | public void onComplete(@NonNull Task task) {
140 | if (task.isSuccessful() && task.getResult() != null) {
141 | mLocation = task.getResult();
142 | Log.i(TAG, "getLastLocation " + mLocation);
143 | // Toast.makeText(getApplicationContext(), "" + mLocation, Toast.LENGTH_SHORT).show();
144 | onNewLocation(mLocation);
145 | } else {
146 | Log.w(TAG, "Failed to get location.");
147 | }
148 | }
149 | });
150 | } catch (SecurityException unlikely) {
151 | Log.e(TAG, "Lost location permission." + unlikely);
152 | }
153 | }
154 |
155 | private void onNewLocation(Location location) {
156 | Log.i(TAG, "New location: " + location);
157 | // Toast.makeText(getApplicationContext(), "onNewLocation " + location, Toast.LENGTH_LONG).show();
158 |
159 | mLocation = location;
160 | if (this.iLocationProvider != null) {
161 | this.iLocationProvider.onLocationUpdate(mLocation);
162 | }
163 | }
164 |
165 | /**
166 | * Sets the location request parameters.
167 | */
168 | private void createLocationRequest() {
169 | mLocationRequest = new LocationRequest();
170 | mLocationRequest.setInterval(UPDATE_INTERVAL_IN_MILLISECONDS);
171 | mLocationRequest.setFastestInterval(FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS);
172 | mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
173 | }
174 |
175 | /**
176 | * implements this interface to get call back of location changes
177 | */
178 | public interface ILocationProvider {
179 | void onLocationUpdate(Location location);
180 | }
181 | }
--------------------------------------------------------------------------------
/locationTrack/src/main/java/app/prior/tracker/LocationUpdatesComponent.java:
--------------------------------------------------------------------------------
1 | package app.prior.tracker;
2 |
3 | import android.content.Context;
4 | import android.location.Location;
5 | import android.os.Looper;
6 | import android.support.annotation.NonNull;
7 | import android.util.Log;
8 |
9 | import com.google.android.gms.location.FusedLocationProviderClient;
10 | import com.google.android.gms.location.LocationCallback;
11 | import com.google.android.gms.location.LocationRequest;
12 | import com.google.android.gms.location.LocationResult;
13 | import com.google.android.gms.location.LocationServices;
14 | import com.google.android.gms.tasks.OnCompleteListener;
15 | import com.google.android.gms.tasks.Task;
16 |
17 |
18 | /**
19 | * stand alone component for location updates
20 | */
21 | public class LocationUpdatesComponent {
22 |
23 | private static final String TAG = LocationUpdatesComponent.class.getSimpleName();
24 |
25 | /**
26 | * The desired interval for location updates. Inexact. Updates may be more or less frequent.
27 | */
28 | private static final long UPDATE_INTERVAL_IN_MILLISECONDS = 3 * 1000;
29 |
30 | /**
31 | * The fastest rate for active location updates. Updates will never be more frequent
32 | * than this value.
33 | */
34 | private static final long FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS =
35 | UPDATE_INTERVAL_IN_MILLISECONDS / 2;
36 |
37 | private LocationRequest mLocationRequest;
38 |
39 | /**
40 | * Provides access to the Fused Location Provider API.
41 | */
42 | private FusedLocationProviderClient mFusedLocationClient;
43 |
44 | /**
45 | * Callback for changes in location.
46 | */
47 | private LocationCallback mLocationCallback;
48 |
49 | /**
50 | * The current location.
51 | */
52 | private Location mLocation;
53 |
54 | public ILocationProvider iLocationProvider;
55 |
56 | public LocationUpdatesComponent(ILocationProvider iLocationProvider) {
57 | this.iLocationProvider = iLocationProvider;
58 | }
59 |
60 | /**
61 | * create first time to initialize the location components
62 | *
63 | * @param context
64 | */
65 | public void onCreate(Context context) {
66 | Log.i(TAG, "created...............");
67 | mFusedLocationClient = LocationServices.getFusedLocationProviderClient(context);
68 |
69 | mLocationCallback = new LocationCallback() {
70 | @Override
71 | public void onLocationResult(LocationResult locationResult) {
72 | super.onLocationResult(locationResult);
73 | Log.i(TAG, "onCreate...onLocationResult...............loc " + locationResult.getLastLocation());
74 |
75 | onNewLocation(locationResult.getLastLocation());
76 | }
77 | };
78 | // create location request
79 | createLocationRequest();
80 | // get last known location
81 | getLastLocation();
82 | }
83 |
84 | /**
85 | * start location updates
86 | */
87 | public void onStart() {
88 | Log.i(TAG, "onStart ");
89 | //hey request for location updates
90 | requestLocationUpdates();
91 | }
92 |
93 | /**
94 | * remove location updates
95 | */
96 | public void onStop() {
97 | Log.i(TAG, "onStop....");
98 | removeLocationUpdates();
99 | }
100 |
101 | /**
102 | * Makes a request for location updates. Note that in this sample we merely log the
103 | * {@link SecurityException}.
104 | */
105 | public void requestLocationUpdates() {
106 | Log.i(TAG, "Requesting location updates");
107 | try {
108 | mFusedLocationClient.requestLocationUpdates(mLocationRequest,
109 | mLocationCallback, Looper.getMainLooper());
110 | } catch (SecurityException unlikely) {
111 | Log.e(TAG, "Lost location permission. Could not request updates. " + unlikely);
112 | }
113 | }
114 |
115 | /**
116 | * Removes location updates. Note that in this sample we merely log the
117 | * {@link SecurityException}.
118 | */
119 | public void removeLocationUpdates() {
120 | Log.i(TAG, "Removing location updates");
121 | try {
122 | mFusedLocationClient.removeLocationUpdates(mLocationCallback);
123 | // Utils.setRequestingLocationUpdates(this, false);
124 | // stopSelf();
125 | } catch (SecurityException unlikely) {
126 | // Utils.setRequestingLocationUpdates(this, true);
127 | Log.e(TAG, "Lost location permission. Could not remove updates. " + unlikely);
128 | }
129 | }
130 |
131 | /**
132 | * get last location
133 | */
134 | private void getLastLocation() {
135 | try {
136 | mFusedLocationClient.getLastLocation()
137 | .addOnCompleteListener(new OnCompleteListener() {
138 | @Override
139 | public void onComplete(@NonNull Task task) {
140 | if (task.isSuccessful() && task.getResult() != null) {
141 | mLocation = task.getResult();
142 | Log.i(TAG, "getLastLocation " + mLocation);
143 | // Toast.makeText(getApplicationContext(), "" + mLocation, Toast.LENGTH_SHORT).show();
144 | onNewLocation(mLocation);
145 | } else {
146 | Log.w(TAG, "Failed to get location.");
147 | }
148 | }
149 | });
150 | } catch (SecurityException unlikely) {
151 | Log.e(TAG, "Lost location permission." + unlikely);
152 | }
153 | }
154 |
155 | private void onNewLocation(Location location) {
156 | Log.i(TAG, "New location: " + location);
157 | // Toast.makeText(getApplicationContext(), "onNewLocation " + location, Toast.LENGTH_LONG).show();
158 |
159 | mLocation = location;
160 | if (this.iLocationProvider != null) {
161 | this.iLocationProvider.onLocationUpdate(mLocation);
162 | }
163 | }
164 |
165 | /**
166 | * Sets the location request parameters.
167 | */
168 | private void createLocationRequest() {
169 | mLocationRequest = new LocationRequest();
170 | mLocationRequest.setInterval(UPDATE_INTERVAL_IN_MILLISECONDS);
171 | mLocationRequest.setFastestInterval(FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS);
172 | mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
173 | }
174 |
175 | /**
176 | * implements this interface to get call back of location changes
177 | */
178 | public interface ILocationProvider {
179 | void onLocationUpdate(Location location);
180 | }
181 | }
--------------------------------------------------------------------------------
/app/src/main/java/dpm/location/tracker/JobServiceDemoActivity.java:
--------------------------------------------------------------------------------
1 | package dpm.location.tracker;
2 |
3 | import android.Manifest;
4 | import android.content.Intent;
5 | import android.content.pm.PackageManager;
6 | import android.location.Location;
7 | import android.os.Bundle;
8 | import android.os.Handler;
9 | import android.os.Message;
10 | import android.os.Messenger;
11 | import android.support.annotation.NonNull;
12 | import android.support.design.widget.NavigationView;
13 | import android.support.v4.app.ActivityCompat;
14 | import android.support.v4.view.GravityCompat;
15 | import android.support.v4.widget.DrawerLayout;
16 | import android.support.v7.app.ActionBarDrawerToggle;
17 | import android.support.v7.app.AppCompatActivity;
18 | import android.support.v7.widget.Toolbar;
19 | import android.util.Log;
20 | import android.view.Menu;
21 | import android.view.MenuItem;
22 | import android.widget.TextView;
23 |
24 | import java.text.DateFormat;
25 | import java.util.Date;
26 |
27 | import static android.support.v4.widget.DrawerLayout.LOCK_MODE_LOCKED_CLOSED;
28 |
29 | public class JobServiceDemoActivity extends AppCompatActivity
30 | implements NavigationView.OnNavigationItemSelectedListener {
31 | private static final String TAG = JobServiceDemoActivity.class.getSimpleName();
32 |
33 | /**
34 | * Code used in requesting runtime permissions.
35 | */
36 | private static final int REQUEST_PERMISSIONS_REQUEST_CODE = 34;
37 |
38 | public static final String MESSENGER_INTENT_KEY = "msg-intent-key";
39 |
40 | private TextView locationMsg;
41 |
42 | // as google doc says
43 | // Handler for incoming messages from the service.
44 | private IncomingMessageHandler mHandler;
45 |
46 | @Override
47 | protected void onCreate(Bundle savedInstanceState) {
48 | super.onCreate(savedInstanceState);
49 | setContentView(R.layout.activity_job_service_demo);
50 | Toolbar toolbar = findViewById(R.id.toolbar);
51 | setSupportActionBar(toolbar);
52 |
53 | DrawerLayout drawer = findViewById(R.id.drawer_layout);
54 | ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
55 | this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
56 | drawer.addDrawerListener(toggle);
57 | toggle.syncState();
58 |
59 | NavigationView navigationView = findViewById(R.id.nav_view);
60 | navigationView.setNavigationItemSelectedListener(this);
61 |
62 | drawer.setDrawerLockMode(LOCK_MODE_LOCKED_CLOSED);
63 |
64 | locationMsg = findViewById(R.id.location);
65 |
66 | mHandler = new IncomingMessageHandler();
67 |
68 |
69 | requestPermissions();
70 |
71 | }
72 |
73 | /**
74 | * Callback received when a permissions request has been completed.
75 | */
76 | @Override
77 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
78 | @NonNull int[] grantResults) {
79 | Log.i(TAG, "onRequestPermissionResult");
80 | if (requestCode == REQUEST_PERMISSIONS_REQUEST_CODE) {
81 | if (grantResults.length <= 0) {
82 | // If user interaction was interrupted, the permission request is cancelled and you
83 | // receive empty arrays.
84 | Log.i(TAG, "User interaction was cancelled.");
85 | finish();
86 | } else if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
87 | // can be schedule in this way also
88 | // Utils.scheduleJob(this, LocationUpdatesService.class);
89 | //doing this way to communicate via messenger
90 | // Start service and provide it a way to communicate with this class.
91 | Intent startServiceIntent = new Intent(this, LocationUpdatesService.class);
92 | Messenger messengerIncoming = new Messenger(mHandler);
93 | startServiceIntent.putExtra(MESSENGER_INTENT_KEY, messengerIncoming);
94 | startService(startServiceIntent);
95 | } else {
96 | // Permission denied.
97 | finish();
98 | }
99 | }
100 | }
101 |
102 | @Override
103 | protected void onStart() {
104 | super.onStart();
105 | }
106 |
107 | @Override
108 | protected void onDestroy() {
109 | super.onDestroy();
110 | mHandler = null;
111 | }
112 |
113 | @Override
114 | public void onBackPressed() {
115 | DrawerLayout drawer = findViewById(R.id.drawer_layout);
116 | if (drawer.isDrawerOpen(GravityCompat.START)) {
117 | drawer.closeDrawer(GravityCompat.START);
118 | } else {
119 | super.onBackPressed();
120 | }
121 | }
122 |
123 | @Override
124 | public boolean onCreateOptionsMenu(Menu menu) {
125 | // Inflate the menu; this adds items to the action bar if it is present.
126 | getMenuInflater().inflate(R.menu.job_service_demo, menu);
127 | return true;
128 | }
129 |
130 | @Override
131 | public boolean onOptionsItemSelected(MenuItem item) {
132 | // Handle action bar item clicks here. The action bar will
133 | // automatically handle clicks on the Home/Up button, so long
134 | // as you specify a parent activity in AndroidManifest.xml.
135 | int id = item.getItemId();
136 |
137 | //noinspection SimplifiableIfStatement
138 | if (id == R.id.action_settings) {
139 | return true;
140 | }
141 |
142 | return super.onOptionsItemSelected(item);
143 | }
144 |
145 | @SuppressWarnings("StatementWithEmptyBody")
146 | @Override
147 | public boolean onNavigationItemSelected(MenuItem item) {
148 | // Handle navigation view item clicks here.
149 | int id = item.getItemId();
150 |
151 | if (id == R.id.nav_camera) {
152 | // Handle the camera action
153 | } else if (id == R.id.nav_gallery) {
154 |
155 | } else if (id == R.id.nav_slideshow) {
156 |
157 | } else if (id == R.id.nav_manage) {
158 |
159 | } else if (id == R.id.nav_share) {
160 |
161 | } else if (id == R.id.nav_send) {
162 |
163 | }
164 |
165 | DrawerLayout drawer = findViewById(R.id.drawer_layout);
166 | drawer.closeDrawer(GravityCompat.START);
167 | return true;
168 |
169 | }
170 |
171 | class IncomingMessageHandler extends Handler {
172 | @Override
173 | public void handleMessage(Message msg) {
174 | Log.i(TAG, "handleMessage..." + msg.toString());
175 |
176 | super.handleMessage(msg);
177 |
178 | switch (msg.what) {
179 | case LocationUpdatesService.LOCATION_MESSAGE:
180 | Location obj = (Location) msg.obj;
181 | String currentDateTimeString = DateFormat.getDateTimeInstance().format(new Date());
182 | locationMsg.setText("LAT : " + obj.getLatitude() + "\nLNG : " + obj.getLongitude() + "\n\n" + obj.toString() + " \n\n\nLast updated- " + currentDateTimeString);
183 | break;
184 | }
185 | }
186 | }
187 |
188 | private void requestPermissions() {
189 | boolean shouldProvideRationale =
190 | ActivityCompat.shouldShowRequestPermissionRationale(this,
191 | Manifest.permission.ACCESS_FINE_LOCATION);
192 |
193 | // Provide an additional rationale to the user. This would happen if the user denied the
194 | // request previously, but didn't check the "Don't ask again" checkbox.
195 | if (shouldProvideRationale) {
196 | Log.i(TAG, "Displaying permission rationale to provide additional context.");
197 | // Request permission
198 | ActivityCompat.requestPermissions(JobServiceDemoActivity.this,
199 | new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
200 | REQUEST_PERMISSIONS_REQUEST_CODE);
201 | } else {
202 | Log.i(TAG, "Requesting permission");
203 | // Request permission. It's possible this can be auto answered if device policy
204 | // sets the permission in a given state or the user denied the permission
205 | // previously and checked "Never ask again".
206 | ActivityCompat.requestPermissions(JobServiceDemoActivity.this,
207 | new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
208 | REQUEST_PERMISSIONS_REQUEST_CODE);
209 | }
210 | }
211 | }
212 |
--------------------------------------------------------------------------------