Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何使悬挂式帐篷触发我的接收器?_Android_Kotlin_Android Geofence - Fatal编程技术网

Android 如何使悬挂式帐篷触发我的接收器?

Android 如何使悬挂式帐篷触发我的接收器?,android,kotlin,android-geofence,Android,Kotlin,Android Geofence,因此,我在我的应用程序中使用GeoFence。我在谷歌地图上有树的位置,这三个都是地理围栏 到目前为止,它们已成功构建并添加到我的应用程序中,但当我进入地理围栏区域时,没有触发 位置权限正在工作,所以我认为这不是他们的问题,因此我不会发布他们 我遵循android文档中的官方教程- 为什么触发器不起作用 这是我的密码: OnCreate() 请求 private fun getGeofencingRequest(): GeofencingRequest { re

因此,我在我的应用程序中使用GeoFence。我在谷歌地图上有树的位置,这三个都是地理围栏

到目前为止,它们已成功构建并添加到我的应用程序中,但当我进入地理围栏区域时,没有触发

位置权限正在工作,所以我认为这不是他们的问题,因此我不会发布他们

我遵循android文档中的官方教程-

为什么触发器不起作用

这是我的密码:

OnCreate()

请求

     private fun getGeofencingRequest(): GeofencingRequest {
            return GeofencingRequest.Builder().apply {
                setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER)
                addGeofences(geofenceList)
            }.build()
        }
意图。不会触发接收器

      private val geofencePendingIntent: PendingIntent by lazy {
            val intent = Intent(this, GeofenceBroadcastReceiver::class.java)
            // We use FLAG_UPDATE_CURRENT so that we get the same pending intent back when calling
            // addGeofences() and removeGeofences().
            PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)

        }
添加地理围栏

     private fun addGeofencesToClient(){
            geofencingClient?.addGeofences(getGeofencingRequest(), geofencePendingIntent)?.run {
                addOnSuccessListener {
                    // Geofences added
                    // ...
                    Log.i("added","GEOFENCES ADDED")
                    Toast.makeText(this@MapsActivity, R.string.geofences_added,
                        Toast.LENGTH_SHORT)
                        .show()
                }
                addOnFailureListener {
                    // Failed to add geofences
                    // ...
                    println(it.localizedMessage)
                    Log.i("failed","NOT ADDED")
                }
            }
        }

它实际上在工作。我需要做的是在模拟器上打开GoogleMaps,因为它显然需要这样才能得到你的位置

嗨,菲菲,你创建了JobIntentService吗?嗨,我刚想出来。它实际上在工作。我必须在模拟器上打开谷歌地图,否则它无法获取我的位置。然后,您可以使用假位置应用程序或将新位置发送到emulator。
     private fun addGeofencesToClient(){
            geofencingClient?.addGeofences(getGeofencingRequest(), geofencePendingIntent)?.run {
                addOnSuccessListener {
                    // Geofences added
                    // ...
                    Log.i("added","GEOFENCES ADDED")
                    Toast.makeText(this@MapsActivity, R.string.geofences_added,
                        Toast.LENGTH_SHORT)
                        .show()
                }
                addOnFailureListener {
                    // Failed to add geofences
                    // ...
                    println(it.localizedMessage)
                    Log.i("failed","NOT ADDED")
                }
            }
        }