Android:设备位置已启用时,FusedLocationProviderClient不会调用onLocationResult()

时间:2019-06-12 15:24:14

标签: android google-maps fusedlocationproviderclient

我最近开始凝视问题,因为当设备位置已启用时,我的@ExperimentalCoroutinesApi class ViewModelTest { private val testDispatcher = TestCoroutineDispatcher() private val testScope = TestCoroutineScope(testDispatcher) @Before fun before() { Dispatchers.setMain(testDispatcher) } @After fun after() { Dispatchers.resetMain() testScope.cleanupTestCoroutines() } @Test fun testYourFunc() = testScope.runBlockingTest { val mockRepo = mock<MyRepository> { onBlocking { makeCountryApiCallAsync("") } doReturn Response.success(listOf()) } val viewModel = TheViewModel(mockRepo) val result = viewModel.makeCountriesApiCall() // Or however you can retrieve actual changes the repo made to viewmodel // assert your case } } 没有调用FusedLocationProviderClient的{​​{1}}方法,但是当我启用设备位置时没有问题请用户先启用自己的位置(首先禁用)。在下面,我发布了从onLocationResult()调用的代码(我没有显示我如何预先获得位置许可):

LocationCallback

此功能在启用预先启用的位置之前没有问题。

0 个答案:

没有答案