GeoFenceの解除は次のような手順で行います。
1. LocationClientクラスのconnectメソッドをコールして、Location Serviceに接続 2. 接続完了後、removeGeofencesメソッドをコールして、GeoFenceを解除 3. 解除結果はOnRemoveGeofencesResultListenerリスナーで受け取るremoveGeofencesメソッドは2種類あり、GeoFenceのIDを指定(リクエストID)するメソッドとPendingIntentを指定するメソッドがあります。
public void removeGeofences(List<String> geofenceRequestIds, LocationClient.OnRemoveGeofencesResultListener listener) public void removeGeofences(PendingIntent pendingIntent, LocationClient.OnRemoveGeofencesResultListener listener)
次はGeoFenceのIDを指定(リクエストID)して解除を行うプログラムです。
@Override public void onConnected(Bundle bundle) { super.onConnected(bundle); Bundle fragmentBundle = getArguments(); ArrayList<GeoFenceData> list = fragmentBundle.getParcelableArrayList(GEOFENCE_DATA); List<String> idList = new ArrayList<String>(); for (GeoFenceData data : list) { idList.add(data.getId()); } getLocationClient().removeGeofences(idList, mOnRemoveGeofencesResultListener); }
指定するクラスにより、OnRemoveGeofencesResultListenerリスナーの呼ばれるメソッドが異なります。
メソッド | 内容 |
---|---|
onRemoveGeofencesByPendingIntentResult | GeoFenceのID指定による削除用 |
onRemoveGeofencesByRequestIdsResult | PendingIntent指定による削除用 |
次はonRemoveGeofencesByRequestIdsResultメソッドで結果を受け取るプログラムです。
private OnRemoveGeofencesResultListener mOnRemoveGeofencesResultListener = new OnRemoveGeofencesResultListener() { @Override public void onRemoveGeofencesByPendingIntentResult(int statusCode, PendingIntent pendingIntent) { // TODO Auto-generated method stub } @Override public void onRemoveGeofencesByRequestIdsResult(int statusCode, String[] geofenceRequestIds) { switch (statusCode) { case LocationStatusCodes.SUCCESS: Toast.makeText(getActivity(), "LocationStatusCodes.SUCCESS", Toast.LENGTH_LONG) .show(); break; case LocationStatusCodes.GEOFENCE_NOT_AVAILABLE: case LocationStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES: case LocationStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS: case LocationStatusCodes.ERROR: break; default: break; } mLocationClient.disconnect(); mOnGeoFenceRemoverInterface.onGeoFenceRemoved(); } };
0 件のコメント:
コメントを投稿