For all three question the answer is yes.
The first one, you can determine the accuracy you want to get in the Builder of Geofence, like this
new Geofence.Builder()
.setRequestId(key)
.setCircularRegion(lat, lang, 150)
.setExpirationDuration(Geofence.NEVER_EXPIRE)
.setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER)
.setLoiteringDelay(1000)
.build();
I set the accuracy for 150m(there is one thing you should know is that the more accuracy you set the more power you use)
For the second and third one, you can set the TransitionTypes to Geofence.GEOFENCE_TRANSITION_DWELL to know whether the user is stay in one place for a time. At the same time, you can use PendingIntent to send a broadcast when this condition match. The complete code is as below
Geofence geofence = getGeofence(lat, lng, key);
geofencingClient.addGeofences(
getGeofencingRequest(geofence),
getGeofencePendingIntent(title, location, id))
.addOnCompleteListener(task -> {
if (task.isSuccessful()) {
}else{
}
});
The code of getGeofencingRequest
private GeofencingRequest getGeofencingRequest(Geofence geofence) {
GeofencingRequest.Builder builder = new GeofencingRequest.Builder();
builder.setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER);
builder.addGeofence(geofence);
return builder.build();
}
The code of getGeofencePendingIntent
private PendingIntent getGeofencePendingIntent(String title, String location, long id) {
Intent i = new Intent("add your unique ID for the broadcast");
Bundle bundle = new Bundle();
bundle.putLong(Reminder.ID, id);
bundle.putString(Reminder.LOCATION_NAME, location);
bundle.putString(Reminder.TITLE, title);
i.putExtras(bundle);
return PendingIntent.getBroadcast(
getContext(),
(int) id,
i,
0
);
}