FusedLocationProviderClient With Service Android Kotlin

﹥>﹥吖頭↗ 提交于 2019-12-24 12:05:09

问题


I am using Fused Api for location update. I am using Fused Api with Activity is working fine. But when i use it within service class its showing This is my Service class code . Where error occurring


回答1:


Class Task (https://developers.google.com/android/reference/com/google/android/gms/tasks/Task) have three overloads of method addOnCompleteListener:

  • addOnCompleteListener(OnCompleteListener<TResult> listener)
  • addOnCompleteListener(Activity activity, OnCompleteListener<TResult> listener)
  • addOnCompleteListener(Executor executor, OnCompleteListener<TResult> listener)

Your Service is neither Activity, nor Executor. So the two latter overloads are not applicable for you. Just drop the first parameter and use it like that:

mFusedLocationClient!!.lastLocation.addOnCompleteListener { task -> //do something }



来源:https://stackoverflow.com/questions/45322675/fusedlocationproviderclient-with-service-android-kotlin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!