我的地理围栏正在工作,但地理围栏过渡对象为空

问题描述 投票:0回答:1
android kotlin background location geofencing
1个回答
0
投票

1。检查意图操作

<receiver
    android:name=".GeofenceBroadcastReceiver"
    android:exported="true">
    <intent-filter>
        <action android:name="com.google.android.gms.location.ACTION_GEOFENCE_TRANSITION" />
    </intent-filter>
</receiver>

在您的 GeofenceBroadcastReceiver 中,检查以下内容:

if (intent?.action == "com.google.android.gms.location.ACTION_GEOFENCE_TRANSITION") {
    // Your geofence processing code here
}

2。检查地理围栏事件错误

val geofencingEvent = GeofencingEvent.fromIntent(intent)
if (geofencingEvent.hasError()) {
    val errorMessage = GeofenceStatusCodes.getStatusCodeString(geofencingEvent.errorCode)
    Log.e(TAGED, "Geofencing error: $errorMessage")
    return
}
© www.soinside.com 2019 - 2024. All rights reserved.