Problem requesting location updates by network

强颜欢笑 提交于 2019-12-22 04:50:11

问题


I've created a Service and grabs location data about the user so I can show my users nearby places. I want this Service to track by network in addition to GPS for 2 reasons: 1) GPS may not be enabled. 2) GPS takes quite a bit of time to lock on with my test phone.

When my Service executes the following line:

mNETEnabled = mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);

I get the following error:

11-24 14:00:41.693: ERROR/LocationManagerService(51): isProviderEnabled got exception:
11-24 14:00:41.693: ERROR/LocationManagerService(51): java.lang.IllegalArgumentException: provider=network
11-24 14:00:41.693: ERROR/LocationManagerService(51):     at com.android.server.LocationManagerService._isProviderEnabledLocked(LocationManagerService.java:1385)
11-24 14:00:41.693: ERROR/LocationManagerService(51):     at com.android.server.LocationManagerService.isProviderEnabled(LocationManagerService.java:1359)

Why is this? Am I missing a permission from the Manifest? I have ACCESS_COARSE_LOCATION in my manifest.


回答1:


are you running on emulator at api level 13 or greater? Android issue 19857




回答2:


Use wireless networks setting in Security & location preference settings. Is it enabled?




回答3:


Could be that the Moment doesn't have AGPS (which would be weird). But you can check with using LocationManager.getAllProviders() and see which ones come back. You could also just use LocationManager.getBestProvider (Criteria criteria, boolean enabledOnly)'.



来源:https://stackoverflow.com/questions/4271041/problem-requesting-location-updates-by-network

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