触发后如何删除特定的地理围栏

问题描述

场景:下面提到的代码片段显示一个 broadcastReciver,它的工作是在输入添加的地理围栏时启动服务。然后启动 JobIntentService,它使用传递的字符串执行一些操作,然后使用数据触发通知

要做什么:我希望,在许多其他添加的地理围栏中,当特定的地理围栏被触发时,应该将其移除以防止重新触发。

问题:如何在上述场景中实现这一点?

以下截图供参考


class GeofencebroadcastReceiver : broadcastReceiver() {

    override fun onReceive(context: Context,intent: Intent) {
        if (intent.action == ACTION_GEOFENCE_EVENT) {

            val geoFencingEvent = GeofencingEvent.fromIntent(intent)

            if (geoFencingEvent.hasError()) {
                Timber.i("Error while activating Geofencing: ${geoFencingEvent.errorCode}")
                return
            } else {

                val geoFenceTransition = geoFencingEvent.geofenceTransition

                if (geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER) {
                    val geofenceId = geoFencingEvent.triggeringGeofences[0].requestId

                    val jobIntent = Intent(context,GeofenceTransitionsJobIntentService::class.java)
                        .putExtra("REMINDER_ID",geofenceId)
                    GeofenceTransitionsJobIntentService.enqueueWork(context,jobIntent)
                }
            }
        }
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)