Android to update geofence regularly
up vote
0
down vote
favorite
I am reading through documentation from here.
https://developer.android.com/training/location/geofencing
It can update me location for my geofence when I run that service. Problem is I need to monitor continuously. So, I am thinking to do timer in my service and check my geofence regularly. But, I think it will definitely drain battery.
I don't want to monitor location and instead, I need android OS to update me whether user goes inside my geofence just like iOS. Is there any way to implement that ?
public class GeofenceTransitionsIntentService extends IntentService {
// ...
protected void onHandleIntent(Intent intent) {
GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
if (geofencingEvent.hasError()) {
String errorMessage = GeofenceErrorMessages.getErrorString(this,
geofencingEvent.getErrorCode());
Log.e(TAG, errorMessage);
return;
}
// Get the transition type.
int geofenceTransition = geofencingEvent.getGeofenceTransition();
// Test that the reported transition was of interest.
if (geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ||
geofenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT) {
// Get the geofences that were triggered. A single event can trigger
// multiple geofences.
List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences();
// Get the transition details as a String.
String geofenceTransitionDetails = getGeofenceTransitionDetails(
this,
geofenceTransition,
triggeringGeofences
);
// Send notification and log the transition details.
sendNotification(geofenceTransitionDetails);
Log.i(TAG, geofenceTransitionDetails);
} else {
// Log the error.
Log.e(TAG, getString(R.string.geofence_transition_invalid_type,
geofenceTransition));
}
}
android geolocation android-location
add a comment |
up vote
0
down vote
favorite
I am reading through documentation from here.
https://developer.android.com/training/location/geofencing
It can update me location for my geofence when I run that service. Problem is I need to monitor continuously. So, I am thinking to do timer in my service and check my geofence regularly. But, I think it will definitely drain battery.
I don't want to monitor location and instead, I need android OS to update me whether user goes inside my geofence just like iOS. Is there any way to implement that ?
public class GeofenceTransitionsIntentService extends IntentService {
// ...
protected void onHandleIntent(Intent intent) {
GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
if (geofencingEvent.hasError()) {
String errorMessage = GeofenceErrorMessages.getErrorString(this,
geofencingEvent.getErrorCode());
Log.e(TAG, errorMessage);
return;
}
// Get the transition type.
int geofenceTransition = geofencingEvent.getGeofenceTransition();
// Test that the reported transition was of interest.
if (geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ||
geofenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT) {
// Get the geofences that were triggered. A single event can trigger
// multiple geofences.
List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences();
// Get the transition details as a String.
String geofenceTransitionDetails = getGeofenceTransitionDetails(
this,
geofenceTransition,
triggeringGeofences
);
// Send notification and log the transition details.
sendNotification(geofenceTransitionDetails);
Log.i(TAG, geofenceTransitionDetails);
} else {
// Log the error.
Log.e(TAG, getString(R.string.geofence_transition_invalid_type,
geofenceTransition));
}
}
android geolocation android-location
You don't need to monitor geofence continuously. Create geofence and sit back, Geofence will notify you when you are in the geofence area.
– Dhaval Patel
Nov 15 at 4:24
Where shall I create geofence? In main activity or service? It is because user can kill app.
– Khant Thu Linn
Nov 15 at 5:01
I am not sure about your app workflow. But maybe you can create geofence when your app starts. Once you create the geofence, even if the user kills the app, You will be notified.
– Dhaval Patel
Nov 15 at 5:04
ah okay. let me try. there is one thing I don't understand. Do I need to start GeofenceTransitionsIntentService ? Or mGeofencingClient will invoke GeofenceTransitionsIntentService automatically?
– Khant Thu Linn
Nov 15 at 5:40
You don't need to start GeofenceTransitionsIntentService. You need to specify this service while creating Geofence. Geofence will invoke the service for you.
– Dhaval Patel
Nov 15 at 5:43
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am reading through documentation from here.
https://developer.android.com/training/location/geofencing
It can update me location for my geofence when I run that service. Problem is I need to monitor continuously. So, I am thinking to do timer in my service and check my geofence regularly. But, I think it will definitely drain battery.
I don't want to monitor location and instead, I need android OS to update me whether user goes inside my geofence just like iOS. Is there any way to implement that ?
public class GeofenceTransitionsIntentService extends IntentService {
// ...
protected void onHandleIntent(Intent intent) {
GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
if (geofencingEvent.hasError()) {
String errorMessage = GeofenceErrorMessages.getErrorString(this,
geofencingEvent.getErrorCode());
Log.e(TAG, errorMessage);
return;
}
// Get the transition type.
int geofenceTransition = geofencingEvent.getGeofenceTransition();
// Test that the reported transition was of interest.
if (geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ||
geofenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT) {
// Get the geofences that were triggered. A single event can trigger
// multiple geofences.
List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences();
// Get the transition details as a String.
String geofenceTransitionDetails = getGeofenceTransitionDetails(
this,
geofenceTransition,
triggeringGeofences
);
// Send notification and log the transition details.
sendNotification(geofenceTransitionDetails);
Log.i(TAG, geofenceTransitionDetails);
} else {
// Log the error.
Log.e(TAG, getString(R.string.geofence_transition_invalid_type,
geofenceTransition));
}
}
android geolocation android-location
I am reading through documentation from here.
https://developer.android.com/training/location/geofencing
It can update me location for my geofence when I run that service. Problem is I need to monitor continuously. So, I am thinking to do timer in my service and check my geofence regularly. But, I think it will definitely drain battery.
I don't want to monitor location and instead, I need android OS to update me whether user goes inside my geofence just like iOS. Is there any way to implement that ?
public class GeofenceTransitionsIntentService extends IntentService {
// ...
protected void onHandleIntent(Intent intent) {
GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
if (geofencingEvent.hasError()) {
String errorMessage = GeofenceErrorMessages.getErrorString(this,
geofencingEvent.getErrorCode());
Log.e(TAG, errorMessage);
return;
}
// Get the transition type.
int geofenceTransition = geofencingEvent.getGeofenceTransition();
// Test that the reported transition was of interest.
if (geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ||
geofenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT) {
// Get the geofences that were triggered. A single event can trigger
// multiple geofences.
List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences();
// Get the transition details as a String.
String geofenceTransitionDetails = getGeofenceTransitionDetails(
this,
geofenceTransition,
triggeringGeofences
);
// Send notification and log the transition details.
sendNotification(geofenceTransitionDetails);
Log.i(TAG, geofenceTransitionDetails);
} else {
// Log the error.
Log.e(TAG, getString(R.string.geofence_transition_invalid_type,
geofenceTransition));
}
}
android geolocation android-location
android geolocation android-location
edited Nov 15 at 1:54
shizhen
2,4963727
2,4963727
asked Nov 15 at 0:57
Khant Thu Linn
2,01042777
2,01042777
You don't need to monitor geofence continuously. Create geofence and sit back, Geofence will notify you when you are in the geofence area.
– Dhaval Patel
Nov 15 at 4:24
Where shall I create geofence? In main activity or service? It is because user can kill app.
– Khant Thu Linn
Nov 15 at 5:01
I am not sure about your app workflow. But maybe you can create geofence when your app starts. Once you create the geofence, even if the user kills the app, You will be notified.
– Dhaval Patel
Nov 15 at 5:04
ah okay. let me try. there is one thing I don't understand. Do I need to start GeofenceTransitionsIntentService ? Or mGeofencingClient will invoke GeofenceTransitionsIntentService automatically?
– Khant Thu Linn
Nov 15 at 5:40
You don't need to start GeofenceTransitionsIntentService. You need to specify this service while creating Geofence. Geofence will invoke the service for you.
– Dhaval Patel
Nov 15 at 5:43
add a comment |
You don't need to monitor geofence continuously. Create geofence and sit back, Geofence will notify you when you are in the geofence area.
– Dhaval Patel
Nov 15 at 4:24
Where shall I create geofence? In main activity or service? It is because user can kill app.
– Khant Thu Linn
Nov 15 at 5:01
I am not sure about your app workflow. But maybe you can create geofence when your app starts. Once you create the geofence, even if the user kills the app, You will be notified.
– Dhaval Patel
Nov 15 at 5:04
ah okay. let me try. there is one thing I don't understand. Do I need to start GeofenceTransitionsIntentService ? Or mGeofencingClient will invoke GeofenceTransitionsIntentService automatically?
– Khant Thu Linn
Nov 15 at 5:40
You don't need to start GeofenceTransitionsIntentService. You need to specify this service while creating Geofence. Geofence will invoke the service for you.
– Dhaval Patel
Nov 15 at 5:43
You don't need to monitor geofence continuously. Create geofence and sit back, Geofence will notify you when you are in the geofence area.
– Dhaval Patel
Nov 15 at 4:24
You don't need to monitor geofence continuously. Create geofence and sit back, Geofence will notify you when you are in the geofence area.
– Dhaval Patel
Nov 15 at 4:24
Where shall I create geofence? In main activity or service? It is because user can kill app.
– Khant Thu Linn
Nov 15 at 5:01
Where shall I create geofence? In main activity or service? It is because user can kill app.
– Khant Thu Linn
Nov 15 at 5:01
I am not sure about your app workflow. But maybe you can create geofence when your app starts. Once you create the geofence, even if the user kills the app, You will be notified.
– Dhaval Patel
Nov 15 at 5:04
I am not sure about your app workflow. But maybe you can create geofence when your app starts. Once you create the geofence, even if the user kills the app, You will be notified.
– Dhaval Patel
Nov 15 at 5:04
ah okay. let me try. there is one thing I don't understand. Do I need to start GeofenceTransitionsIntentService ? Or mGeofencingClient will invoke GeofenceTransitionsIntentService automatically?
– Khant Thu Linn
Nov 15 at 5:40
ah okay. let me try. there is one thing I don't understand. Do I need to start GeofenceTransitionsIntentService ? Or mGeofencingClient will invoke GeofenceTransitionsIntentService automatically?
– Khant Thu Linn
Nov 15 at 5:40
You don't need to start GeofenceTransitionsIntentService. You need to specify this service while creating Geofence. Geofence will invoke the service for you.
– Dhaval Patel
Nov 15 at 5:43
You don't need to start GeofenceTransitionsIntentService. You need to specify this service while creating Geofence. Geofence will invoke the service for you.
– Dhaval Patel
Nov 15 at 5:43
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53310975%2fandroid-to-update-geofence-regularly%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You don't need to monitor geofence continuously. Create geofence and sit back, Geofence will notify you when you are in the geofence area.
– Dhaval Patel
Nov 15 at 4:24
Where shall I create geofence? In main activity or service? It is because user can kill app.
– Khant Thu Linn
Nov 15 at 5:01
I am not sure about your app workflow. But maybe you can create geofence when your app starts. Once you create the geofence, even if the user kills the app, You will be notified.
– Dhaval Patel
Nov 15 at 5:04
ah okay. let me try. there is one thing I don't understand. Do I need to start GeofenceTransitionsIntentService ? Or mGeofencingClient will invoke GeofenceTransitionsIntentService automatically?
– Khant Thu Linn
Nov 15 at 5:40
You don't need to start GeofenceTransitionsIntentService. You need to specify this service while creating Geofence. Geofence will invoke the service for you.
– Dhaval Patel
Nov 15 at 5:43