Я пытаюсь реализовать механизм Geofencing, в котором отслеживается геозонность, и как только пользователь выходит из текущего геозонда, текущие координаты используются для создания нового запроса geofence и db, инициированного для получения некоторых данные.Ожидаемые намерения не установлены
Моя проблема заключается в том, что ожидающее намерения никогда не срабатывает.
Из журналов я вижу, что геопостановки добавляются в клиент местоположения. Однако никакие ожидающие намерения не увольняются после изменения местоположения (я установил радиус забора на 2 м, и я прошел более 100 м). Что-то не так в том, как я объявил службу намерения?
Вот класс обслуживания намерений.
public class GeoFenceIntentService extends IntentService{
private static final String mIntentName = "GeoFenceIntentService";
public GeoFenceIntentService() {
super(mIntentName);
}
@Override
protected void onHandleIntent(Intent intent) {
int transitionType = LocationClient.getGeofenceTransition(intent);
Log.e(TAG,"Inside fence handler");
if(transitionType == Geofence.GEOFENCE_TRANSITION_EXIT){
//Query DB here with current co-ords
//create new GeoFence
Location location = LocationHelper.getInstance(mContext).getLastLocation();
mLat = String.valueOf(location.getLatitude());
mLong = String.valueOf(location.getLongitude());
addGeofenceToMonitor(location);
queryDb();
}
}
}
Кроме того, здесь, где я добавить ожидающие намерения и Geofence клиенту местонахождения
addGeofenceToMonitor(Location location){
List<Geofence> list = new ArrayList<Geofence>();
list.add(getNewGeofence(location.getLatitude(), location.getLongitude()));
PendingIntent pendingIntent = PendingIntent.getService(mContext, 0,
new Intent(mContext,GeoFenceIntentService.class), PendingIntent.FLAG_UPDATE_CURRENT);
OnRemoveGeofencesResultListener removeListener = new OnRemoveGeofencesResultListener() {
@Override
public void onRemoveGeofencesByRequestIdsResult(int statusCode, String[] requestIDs) {
//To be used
}
@Override
public void onRemoveGeofencesByPendingIntentResult(int statusCode,PendingIntent pendingIntent) {
//Not used
}
};
LocationHelper.getInstance(mContext).removeGeoFence(mGeofenceRequestIDs, removeListener);
OnAddGeofencesResultListener addListener = new OnAddGeofencesResultListener() {
@Override
public void onAddGeofencesResult(int statusCode, String[] geofenceRequestIds) {
if(statusCode != LocationStatusCodes.SUCCESS){
//handle error cases
}
else
Log.i(TAG, "Successfully added Geofence "+geofenceRequestIds[0]+" for monitoring");
}
};
LocationHelper.getInstance(mContext).addGeoFence(list, pendingIntent, addListener);
}
Вот отрывок из файла манифеста
<service
android:name="com.myexample.sample.GeoFenceIntentService"
android:label="@string/app_name"
android:exported="true">
</service>
Вы пытались использовать «BroadcastReceiver» в качестве цели вашего «PendingIntent» вместо «Сервис»? Если нет, попробуйте это и посмотрите, вызывается ли 'onReceive()'. –