我在应用程序中使用了地理围栏,除删除触发的地理围栏外,其他所有功能均正常.
我从Android的官方文档中删除了该指南,但它们没有说明如何删除IntentService内部的地理围栏.
这是服务的事件处理程序的代码:
@OverrIDeprotected voID onHandleIntent(Intent intent) { Log.e("GeofenceIntentService", "Location handled"); if (LocationClIEnt.hasError(intent)) { int errorCode = LocationClIEnt.getErrorCode(intent); Log.e("GeofenceIntentService", "Location Services error: " + Integer.toString(errorCode)); } else { int TransitionType = LocationClIEnt.getGeofenceTransition(intent); if (TransitionType == Geofence.GEOFENCE_Transition_ENTER) { List <Geofence> triggerList = LocationClIEnt.getTriggeringGeofences(intent); String[] triggerIDs = new String[triggerList.size()]; for (int i = 0; i < triggerIDs.length; i++) { // Store the ID of each geofence triggerIDs[i] = triggerList.get(i).getRequestID(); Picture p = PicturesManager.getByID(triggerIDs[i], getApplicationContext()); /* ... do a lot of work here ... */ } } else Log.e("ReceiveTransitionsIntentService", "Geofence Transition error: " + Integer.toString(TransitionType)); }}
他被触发后,如何删除地理围栏?
解决方法:
您可以执行以下 *** 作:
LocationServices.GeofencingAPI.removeGeofences( mGoogleapiclient, // This is the same pending intent that was used in addGeofences(). getGeofencePendingIntent()).setResultCallback(this); // Result processed in onResult().
而且您的getGeofencePendingIntent()方法如下所示:
/** * Gets a PendingIntent to send with the request to add or remove Geofences. Location Services * issues the Intent insIDe this PendingIntent whenever a geofence Transition occurs for the * current List of geofences. * * @return A PendingIntent for the IntentService that handles geofence Transitions. */private PendingIntent getGeofencePendingIntent() { Log.d(TAG, "getGeofencePendingIntent()"); // Reuse the PendingIntent if we already have it. if (mGeofencePendingIntent != null) { return mGeofencePendingIntent; } Intent intent = new Intent(mContext, GeofenceIntentServiceStub.class); // We use FLAG_UPDATE_CURRENT so that we get the same pending intent back when calling // addGeofences() and removeGeofences(). mGeofencePendingIntent = PendingIntent.getService(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); return mGeofencePendingIntent;}
总结 以上是内存溢出为你收集整理的触发后删除地理围栏全部内容,希望文章能够帮你解决触发后删除地理围栏所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)