我刚刚更新了我的Location API以使用FusedLocationProviderClient,但是我遇到了这个问题,当我关闭并在GPS上时,我总是得到null位置:
val fusedLocationProviderClient =
LocationServices.getFusedLocationProviderClient(callingActivity)
fusedLocationProviderClient.flushLocations()
getLocationRequest()
checkLocationSettings(callingActivity, turnOnGpsRequestCode, callback) {
// Location settings successful
fusedLocationProviderClient.lastLocation
.addOnSuccessListener(callingActivity) {
location ->
// Here location is always null
callback.onCallback(MenumyRadar.RadarStatus.SUCCESS, location)
}
.addOnFailureListener {
callback.onCallback(MenumyRadar.RadarStatus.ERROR_UNKNOWN, null)
}
}
Run Code Online (Sandbox Code Playgroud)
直到我打开另一个使用位置的应用程序,如谷歌地图或优步,它才能工作.
我有一些线索感谢这个答案 FusedLocationApi.getLastLocation总是为null
谷歌的解释:
fusedLocationClient.lastLocation .addOnSuccessListener {location:Location? - > //找到最后一个位置.在某些罕见情况下,这可能为空.}
getLastLocation()方法返回一个Task,您可以使用该Task获取具有地理位置的纬度和经度坐标的Location对象.在以下情况下,location对象可能为null:
设备设置中的位置已关闭.即使先前检索过最后一个位置,结果也可能为null,因为禁用位置也会清除缓存.设备从未记录其位置,这可能是新设备或已恢复出厂设置的设备.设备上的Google Play服务已重新启动,并且在重新启动服务后,没有活动的融合位置提供程序客户端请求了位置.为避免这种情况,您可以创建一个新客户端并自行请求位置更新.有关更多信息,请参阅接收位置更新.
但它没有说明如何处理这个问题,我该怎么办?
我正在尝试在 Kotlin 上对此进行测试:
verify(myInterface).doSomething(argumentCaptor.capture())
capture.value.invoke(0L)
Run Code Online (Sandbox Code Playgroud)
doSomething 在哪里:
doSomething((Long) -> Unit)
Run Code Online (Sandbox Code Playgroud)
如何为此创建 ArgumentCaptor?现在我正在做这个
inline fun <reified T : Any> argumentCaptor() = ArgumentCaptor.forClass(T::class.java)!!
val captor = argumentCaptor<(Long) -> Unit>()
verify(mainApiInterface!!).downloadUserProfilePicture(captor.capture())
captor.value.invoke(0L)
Run Code Online (Sandbox Code Playgroud)
但我得到 java.lang.IllegalStateException: captor.capture() must not be null
我也尝试集成 mockito-kotlin,但出现 PowerMockito 错误:
在 org.mockito.internal.MockitoCore 的类层次结构中找不到名为“reported”的实例字段。
要添加 Hilt 模块,您需要执行以下操作:
@Module
@InstallIn(SingletonComponent::class)
abstract class MyModule{
...
}
Run Code Online (Sandbox Code Playgroud)
有不同的范围,例如 ActivityComponent、ViewModelComponent 等,但我不清楚什么时候需要使用与 SingletonComponent 不同的范围,毕竟这涵盖了所有内容并且始终有效。这只是遵循封装的良好实践的问题吗?
当我运行我的容器时,它只是挂在下一行,如果我写
\n\n\n \n\n\n
我明白了
\n\n\n\n\n无法连接到 0.0.0.0 端口 8000:连接拒绝
\n
这是我的 dockerfile
\n\nFROM python:3.6.1\n\n# Set the working directory to /app\nWORKDIR /app\n\n# Copy the current directory contents into the container at /app\nADD . /app\n\nRUN pip3 install -r requirements.txt\n\nCMD ["python3", "dockerizing/manage.py", "runserver", "0.0.0.0:8000"]\nRun Code Online (Sandbox Code Playgroud)\n\n我还尝试通过 docker-compose.yml 文件执行此操作,但再次没有任何反应,我\xc2\xb4ve 搜索了很多,并且 Haven\xc2\xb4t 找到了解决方案,这是 docker-compose.yml
\n\nversion: "3"\nservices:\n web:\n image: app1\n deploy:\n replicas: 5\n resources:\n limits:\n cpus: "0.1"\n memory: 50M\n restart_policy:\n condition: on-failure\n ports:\n - "8000:8000"\n networks:\n - webnet\nnetworks:\n …Run Code Online (Sandbox Code Playgroud) android ×5
dagger-hilt ×1
django ×1
docker ×1
dockerfile ×1
function ×1
kotlin ×1
lambda ×1
mockito ×1