GPS Location on Service - Android [duplicate]

冷暖自知 提交于 2020-01-25 07:44:05

问题


Possible Duplicate:
requestLocationUpdates throws exception

I'm trying to create a service that when the server ask me, send my location. but can not find the way to do it, since everything is a background service. and I do not need to have UI interface. when I call requestUpdate () throws me an error and stops the application

locManager.requestLocationUpdates(
                LocationManager.GPS_PROVIDER, 15000, 0, locationListener);

runException Can't create handler inside thread that has not called Looper.prepare()

How I can run something to update the position from my service? anyone have any example or something to help me? I have not much experience yet.


回答1:


Well, its famous problem, See response in your Exception:

 ... that has not called Looper.prepare()

You need provide application's main looper.

Here is valid implementation:

mLocationManager.requestLocationUpdates(
                                        LocationManager.GPS_PROVIDER,
                                        15000,
                                        0,
                                        locationListener,
                                        Looper.getMainLooper()
                                        );


来源:https://stackoverflow.com/questions/13826399/gps-location-on-service-android

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