Skip to content

Commit ae6ccdd

Browse files
committed
Adds start without activity param
1 parent 8434242 commit ae6ccdd

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ dependencies {
7676
// }))
7777

7878
.start(getBaseContext(), this);
79+
80+
// IF YOU WANT RUN IN SERVICE
81+
// .start(this);
7982
}
8083

8184
@Override

app/src/main/java/br/com/safety/sample/MainActivity.java

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
package br.com.safety.sample;
22

3-
import android.location.Location;
43
import android.os.Bundle;
54
import android.support.annotation.NonNull;
65
import android.support.v7.app.AppCompatActivity;
7-
import android.util.Log;
86
import android.view.View;
97
import android.widget.Button;
108

11-
import br.com.safety.locationlistenerhelper.core.CurrentLocationListener;
12-
import br.com.safety.locationlistenerhelper.core.CurrentLocationReceiver;
139
import br.com.safety.locationlistenerhelper.core.LocationTracker;
1410

1511
public class MainActivity extends AppCompatActivity {
@@ -31,20 +27,7 @@ public void onClick(View v) {
3127
.setInterval(1000)
3228
.setGps(true)
3329
.setNetWork(false)
34-
.currentLocation(new CurrentLocationReceiver(new CurrentLocationListener() {
35-
36-
@Override
37-
public void onCurrentLocation(Location location) {
38-
Log.d("callback", ":onCurrentLocation" + location.getLongitude());
39-
locationTracker.stopLocationService(getBaseContext());
40-
}
41-
42-
@Override
43-
public void onPermissionDiened() {
44-
Log.d("callback", ":onPermissionDiened");
45-
locationTracker.stopLocationService(getBaseContext());
46-
}
47-
})).start(getBaseContext(), MainActivity.this);
30+
.start(getBaseContext());
4831
}
4932
});
5033
}

location-tracker-background/src/main/java/br/com/safety/locationlistenerhelper/core/LocationTracker.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,17 @@ public LocationTracker start(Context context, AppCompatActivity appCompatActivit
9292
return this;
9393
}
9494

95+
public LocationTracker start(Context context) {
96+
startLocationService(context);
97+
98+
if (this.currentLocationReceiver != null) {
99+
IntentFilter intentFilter = new IntentFilter(SettingsLocationTracker.ACTION_CURRENT_LOCATION_BROADCAST);
100+
intentFilter.addAction(SettingsLocationTracker.ACTION_PERMISSION_DEINED);
101+
context.registerReceiver(this.currentLocationReceiver, intentFilter);
102+
}
103+
return this;
104+
}
105+
95106
private void startLocationService(Context context) {
96107
Intent serviceIntent = new Intent(context, LocationService.class);
97108
saveSettingsInLocalStorage(context);

0 commit comments

Comments
 (0)