4

지오 펜스가 모니터링되고 사용자가 현재 지오 펜스를 종료하면 지오 펜스 메커니즘을 구현하려고합니다. 현재 지오 펜스를 사용하여 새로운 지오 펜스를 생성하고 db 쿼리가 일부를 페치하기 위해 시작됩니다 데이터.보류중인 의도가 실행되지 않았습니다.

내 문제는 보류중인 의도가 절대로 발생하지 않는다는 것입니다.

로그에서 지오 펜스가 위치 클라이언트에 추가되는 것을 볼 수 있습니다. 그러나 보류중인 의도는 위치 변경시 해고됩니다 (울타리 반경을 2m로 설정 했으므로 100m 이상 걸었습니다). 의도 서비스를 선언 한 방식에 문제가 있습니까?

다음은 인 텐트 서비스 클래스입니다. 내가 위치 클라이언트

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); 
} 

에 보류중인 의도와 지오 펜스를 추가 할 경우 또한 여기

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(); 
     } 
    }  
} 

다음은 매니페스트 파일

<service 
android:name="com.myexample.sample.GeoFenceIntentService" 
android:label="@string/app_name" 
android:exported="true"> 
</service> 
+0

'Service' 대신에'PendingIntent'의 타겟으로'BroadcastReceiver'를 사용 해보려고 했습니까? 그렇지 않다면,'onReceive()'가 호출되는지보십시오. –

답변

0

Read this에서 미리보기입니다. 현재 위치 추정 원을 확인 했습니까? 모의 위치 앱을 사용하여 정확도 원뿐만 아니라 위치를 설정할 수 있습니다. 귀하의 지오 펜스가 귀하의 포지션 서클을 수용하기에는 너무 작을 수 있으므로 이벤트가 실행되지 않습니다.

0

Android GeoFence는 GPS를 사용하지 않습니다 (API가 너무 끔찍하고 기기의 전력 소모량이 너무 비싸기 때문에). 지오 펜스를 설정 한 다음 GPS를 통해 지오 펜싱을 원할 경우 GPS를 별도로 폴링해야합니다.

GPS 폴링의 핸들러는 null 일 수 있습니다. 폴링은 정확한 정보를 무서운 위치 API에 강제로 넣고 울타리를 트리거합니다.

관련 문제