如果有人知道此案发生了什么,请提供帮助。
我有BroadcastReceiver,它注册到ForegroundService。此BroadcastReceiver会侦听Intent.ACTION_SCREEN_ON,并在收到任何内容后调用startLocationUpdates()。
fun startLocationUpdates(context: Context, entity: LockEntityDB?) {
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(context)
mSettingsClient = LocationServices.getSettingsClient(context)
mLocationCallback = object : LocationCallback() {
override fun onLocationResult(locationResult: LocationResult?) {
super.onLocationResult(locationResult)
val location = locationResult?.lastLocation
locationResult?.let {
saveLocation(context, it.lastLocation)
locationUpdatesCount(context)
}
//something will do with entityDb
}
}
mOneTimeLocationRequest = LocationRequest().apply {
interval = 5 * 1000
fastestInterval = 1000
priority = LocationRequest.PRIORITY_HIGH_ACCURACY
numUpdates = 1
}
val builder = LocationSettingsRequest.Builder()
builder.addLocationRequest(mOneTimeLocationRequest!!)
mLocationSettingsRequest = builder.build()
mSettingsClient
?.checkLocationSettings(mLocationSettingsRequest)
?.addOnSuccessListener {
mFusedLocationClient?.requestLocationUpdates(mOneTimeLocationRequest, mLocationCallback, null)
}
?.addOnFailureListener { e ->
kTimberLog(context, "loc " + e.toString())
}
}
因此,如果用户打开电话,它将发送Intent.ACTION_SCREEN_ON,而FusedLocationProviderClient将更新实际用户位置。
问题是,当用户尝试在5-6倍FusedLocationProviderClient之后尝试打开电话时,再也不会给出任何locationResult了。
第6次所有此locationResult最奇怪的部分,等等,当用户打开MainActivity时,此类将重新出现。
[其他信息:我正在3个模拟器上测试此代码:Nexus 5 API 23,PIXEL 3 API 29,Galaxy Nexus API29。它对于Nexus 5 API 23正常工作。
任何人都知道这种行为的原因是什么?非常感谢]]
[如果有人知道此案发生了什么,请提供帮助。我有BroadcastReceiver,注册到ForegroundService。此BroadcastReceiver将收听Intent.ACTION_SCREEN_ON,并称为...