简体   繁体   中英

Android location API using Google Play Services

I am new to android, I am looking into developing an app that requires to get the user's location.

I have created a service to get the user's location using the LocationManager and send the location to an activity . I am now looking into developing a service that uses the Google Play Services to get the current location. I think the Google Play service will be able to provide better accuracy and battery saving.

I had a look into the training and the sample code on the Google training . It looks like using Google Play service will need to be implemented on activity as the Google Play service utilizes startResolutionForResult() and onActivityResult() which uses activity.

Is it impossible to implement Google Play service on a service ?

Yes it's possible but as you said it's really not recommended. In addition it's not possible at all in some situation. What you could do is to give some notifications to the user if an error is detected instead to silently fail.

Yes all you need in your activity when it first starts is to check if google play services is available or it needs an update to support your app. If everything passes then start your service, if something fails use the startResolutionForResult() to resolve the problem and when they do get resolved succcessfully you can start your service. If they dont get resolved successfully notify the user what the problems is

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM