Android 未触发后台位置更新广播接收器

Android 未触发后台位置更新广播接收器,android,kotlin,fusedlocationproviderapi,Android,Kotlin,Fusedlocationproviderapi,尽管Android文档强烈要求不使用后台位置更新,但我的应用程序确实需要它们,所以我更新了所有内容,以正确请求权限并遵守新规则。现在,一旦我获得ACCESS\u BACKGROUND\u LOCATION权限,我将执行以下操作,从我的初始片段中请求后台位置更新: private fun configureBackgroundLocationTracking() { fusedLocationClient.requestLocationUpdates(createLocationReque

尽管Android文档强烈要求不使用后台位置更新,但我的应用程序确实需要它们,所以我更新了所有内容,以正确请求权限并遵守新规则。现在,一旦我获得
ACCESS\u BACKGROUND\u LOCATION
权限,我将执行以下操作,从我的初始片段中请求后台位置更新:

private fun configureBackgroundLocationTracking() {
    fusedLocationClient.requestLocationUpdates(createLocationRequest(), getPendingIntent())
}

private fun createLocationRequest(): LocationRequest {
    return LocationRequest.create().apply {
        interval = 20000
        fastestInterval = 10000
        priority = LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY
    }
}

private fun getPendingIntent(): PendingIntent {
    val intent = Intent(requireContext(), LocationUpdatesBroadcastReceiver::class.java)
    return PendingIntent.getBroadcast(
        requireContext(),
        0,
        intent,
        PendingIntent.FLAG_UPDATE_CURRENT
    )
}
在我的AndroidManifest中,我声明BroadcastReceiver如下:

<receiver android:name=".LocationUpdatesBroadcastReceiver"
            android:exported="true"
            android:permission="android.permission.ACCESS_BACKGROUND_LOCATION">
    <intent-filter>
        <action android:name="com.herontrack.LOCATION_UPDATE" />
    </intent-filter>
</receiver>
onReceive()
中的日志指令将日志发送到远程记录器(Bugfender)。 当我的应用程序在前台时,一切似乎都正常,我可以看到日志。 但是当它在后台时,就不再有更新了

我仔细检查了权限,我确信当我注册
广播接收器
时,
访问背景位置

我运行的是三星S9和安卓10

我忘了什么吗?从一个片段中执行所有这些操作有问题吗

class LocationUpdatesBroadcastReceiver : BroadcastReceiver() {
    override fun onReceive(context: Context, intent: Intent) {
        val result = LocationResult.extractResult(intent)
        if (result != null) {
            val location = result.lastLocation
            if (location != null) {
                Log.d(TAG, "Received location update: $location")
            }
        }
    }

    companion object {
        private const val TAG = "LUBroadcastReceiver"
    }
}