지오 펜스가 모니터링되고 사용자가 현재 지오 펜스를 종료하면 지오 펜스 메커니즘을 구현하려고합니다. 현재 지오 펜스를 사용하여 새로운 지오 펜스를 생성하고 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>
'Service' 대신에'PendingIntent'의 타겟으로'BroadcastReceiver'를 사용 해보려고 했습니까? 그렇지 않다면,'onReceive()'가 호출되는지보십시오. –