From ae6ccddb0ac40033a16fc7c141013024b82146cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Vieira?= Date: Tue, 2 Jan 2018 16:13:30 -0300 Subject: [PATCH] Adds start without activity param --- README.md | 3 +++ .../br/com/safety/sample/MainActivity.java | 19 +------------------ .../core/LocationTracker.java | 11 +++++++++++ 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index f9b2ea3..9b364fe 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,9 @@ dependencies { // })) .start(getBaseContext(), this); + + // IF YOU WANT RUN IN SERVICE + // .start(this); } @Override diff --git a/app/src/main/java/br/com/safety/sample/MainActivity.java b/app/src/main/java/br/com/safety/sample/MainActivity.java index 900bdda..5f202ed 100644 --- a/app/src/main/java/br/com/safety/sample/MainActivity.java +++ b/app/src/main/java/br/com/safety/sample/MainActivity.java @@ -1,15 +1,11 @@ package br.com.safety.sample; -import android.location.Location; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v7.app.AppCompatActivity; -import android.util.Log; import android.view.View; import android.widget.Button; -import br.com.safety.locationlistenerhelper.core.CurrentLocationListener; -import br.com.safety.locationlistenerhelper.core.CurrentLocationReceiver; import br.com.safety.locationlistenerhelper.core.LocationTracker; public class MainActivity extends AppCompatActivity { @@ -31,20 +27,7 @@ public void onClick(View v) { .setInterval(1000) .setGps(true) .setNetWork(false) - .currentLocation(new CurrentLocationReceiver(new CurrentLocationListener() { - - @Override - public void onCurrentLocation(Location location) { - Log.d("callback", ":onCurrentLocation" + location.getLongitude()); - locationTracker.stopLocationService(getBaseContext()); - } - - @Override - public void onPermissionDiened() { - Log.d("callback", ":onPermissionDiened"); - locationTracker.stopLocationService(getBaseContext()); - } - })).start(getBaseContext(), MainActivity.this); + .start(getBaseContext()); } }); } diff --git a/location-tracker-background/src/main/java/br/com/safety/locationlistenerhelper/core/LocationTracker.java b/location-tracker-background/src/main/java/br/com/safety/locationlistenerhelper/core/LocationTracker.java index 0c28544..86fe0b8 100644 --- a/location-tracker-background/src/main/java/br/com/safety/locationlistenerhelper/core/LocationTracker.java +++ b/location-tracker-background/src/main/java/br/com/safety/locationlistenerhelper/core/LocationTracker.java @@ -92,6 +92,17 @@ public LocationTracker start(Context context, AppCompatActivity appCompatActivit return this; } + public LocationTracker start(Context context) { + startLocationService(context); + + if (this.currentLocationReceiver != null) { + IntentFilter intentFilter = new IntentFilter(SettingsLocationTracker.ACTION_CURRENT_LOCATION_BROADCAST); + intentFilter.addAction(SettingsLocationTracker.ACTION_PERMISSION_DEINED); + context.registerReceiver(this.currentLocationReceiver, intentFilter); + } + return this; + } + private void startLocationService(Context context) { Intent serviceIntent = new Intent(context, LocationService.class); saveSettingsInLocalStorage(context);