首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GeoFencing: BroadcastReceiver未能触发

GeoFencing: BroadcastReceiver未能触发
EN

Stack Overflow用户
提问于 2022-01-11 11:23:58
回答 1查看 329关注 0票数 3

我试图从android developer:https://developer.android.com/codelabs/advanced-android-kotlin-training-geofencing?authuser=2#0上运行这个应用程序。

地学正在增加,但什么也没有触发。我试过检查这个页面:https://simpleinout.helpscoutdocs.com/article/232-my-geofences-arent-working-android,但是我的手机似乎没问题.

当我得到一条“添加地理信息”的日志时,如何才能不触发广播呢?我的模拟器、意图或broadcastReceiver有什么问题吗??

BroadcastReceiver:

代码语言:javascript
复制
class GeofenceBroadcastReceiver : BroadcastReceiver() {

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

            if (geofencingEvent.h

意图:

代码语言:javascript
复制
private val geofencePendingIntent: PendingIntent by lazy {
        val intent = Intent(this, GeofenceBroadcastReceiver::class.java)
        intent.action = ACTION_GEOFENCE_EVENT
        PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
    }

增加地理位置:

代码语言:javascript
复制
addOnCompleteListener {
                // Add the new geofence request with the new geofence
                geofencingClient.addGeofences(geofencingRequest, geofencePendingIntent)?.run {
                    addOnSuccessListener {
                        // Geofences added.

此外,ACCESS_BACKGROUND_LOCATION和ACCESS_FINE_LOCATION的位置“始终允许”。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-01-11 14:21:15

终于弄明白了。密码里什么都没有。在仿真器上测试不起作用(至少对我不起作用,通过单击设置并以这种方式改变位置)

对我起作用的是在一个真正的设备上测试:

location

  • download

  • 转到开发人员设置并从应用程序商店启用模拟

  • Lockito。

  • 返回到开发人员设置(模拟位置),并将应用程序设置为“lockito”。

  • 中设置您想要的任何路径,然后单击play.

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70665948

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档