Sunday, December 14, 2014

Migrating from LocationClient to FusedLocationProviderApi

Update: The documentation on has been updated.

The Google Play Services library on Android includes the Location APIs including the Fused Location Provider, Activity recognition and Geofencing APIs.

The goal of the Fused Location Provider from the documentation:
  • Simple APIs: Lets you specify high-level needs like "high accuracy" or "low power", instead of having to worry about location providers.
  • Immediately available: Gives your apps immediate access to the best, most recent location.
  • Power-efficiency: Minimizes your app's use of power. Based on all incoming location requests and available sensors, fused location provider chooses the most efficient way to meet those needs.
  • Versatility: Meets a wide range of needs, from foreground uses that need highly accurate location to background uses that need periodic location updates with negligible power impact.
The use of the location APIs is documented in a training tutorial called Making Your App Location Aware. Unfortunately, with recent updates of the Google Play Services library (version 6.5.+ at the moment) the tutorial is now outdated and doesn't work. The tutorials use the LocationClient class. The class was first deprecated then removed in version 6.5. When the class was deprecated, in the documentation, Google recommended to use the FusedLocationProviderApi instead.

LocationClient removed in version 6.5

Receiving Location Updates

The high level approach for receiving location updates is: 
  1. Request Location Permission
  2. Check for Google Play Services
  3. Define Location Services Callbacks
  4. Specify Update Parameters
  5. Start Location Updates
  6. Stop Location Updates
There are no differences between the LocationClient and FusedLocationProviderApi in steps 1, 2 and 4. The difference is in steps 3, 5 and 6.

Using the LocationClient

A striped down version of the code using the LocationClient looks like this:

Using the FusedLocationProviderApi

A striped down version of the code using the FusedLocationProviderApi looks like this:

Key differences

  1. ConnectionCallback interface from the GooglePlayServicesClient replaced with the ConnectionCallback interface from GoogleApiClient
  2. OnConnectionFailedListener interface from the GooglePlayServicesClient replaced with the OnConnectionFailedListener interface from GoogleApiClient
  3. Create a GoogleApiClient instead of LocationClient in onCreate
  4. In onStart and onStop use the GoogleApiClient instead of the LocationClient
  5. In onConnected use LocationServices.FusedLocationApi to request location updates
The switch from LocationServices to FusedLocationProviderApi shouldn't take more than a few minutes if you know what are you doing. Since Google are stubbornly refusing to document it I decided to write this blog post. I hope you find it useful.

Update: You can star this issue on the android bug tracker and maybe Google will fix the documentation. 

Tuesday, March 4, 2014

Star Falldown released

Almost a year ago, after creating a few apps for Android, I decided to make my fist game for Android. I didn't want to start from scratch so I decided to use a game engine. A friend of mine had experience with AndEngine and he recommended it.

I started experimenting with the engine and I liked how it worked. So I decided to make a game with it. I decided to make a Falldown clone. While I was making the game, the game evolved. I also took breaks to work on other projects.

A few days ago I launched a public beta, you can find out more about that here. About 20 people tested the game and I didn't find any serious problem. I want to thank everybody who tested the game.  I'm happy with how the game looks and I decided to publish it today.

Star Falldown
You can download the game form the Play Store.

I also want to thank my friend Paul G. Lux from Portugal who made the music and helped me with the promo video.

If you like the game don't forget to rate it and/or leave a review on the Play Store.

Friday, February 28, 2014

Coming soon - Star Falldown

Almost a year ago I started developing my first game for Android. It was a Falldown clone called Star Falldown. I decided yo use AndEngine to build the game.
Star Falldown
It's a simple game. You control a ball by tilting your phone. If the ball touches the top of the screen you lose. On your way down, to help you, there are three power ups:

  • Timer - slows down the platforms
  • Ghost - you go trough the platfroms
  • 2x - you get double points
The game includes achievements and leaderboards powered by Google Play Game Services.

The game is in beta, if you want to test it you can use the this link but first make sure you are a member of the Android Beta Testers community.

If you have any suggestions, comments or ideas to make the game better leave a comment bellow or contact me on Google+.

Friday, February 7, 2014

Porting a Google Play app to the Amazon Store

Recently I worked on a project to port and Android app, created for Google Play, to the Amazon app store. It was a simple two-screen app that loaded text from a local database. It included ads (banner and interstitial), in-app purchase for removing the ads and push notifications.

First I uploaded the app to Amazon's app testing service. The only problem the testing service found was the In-App billing API. The suggestion was to use Amazon's In-App purchasing API.

Implementing the Amazon In-App purchasing API was pretty straightforward. Compared to Google's In-App billing API there is one more product type, Entitlement. It's used for something you buy once and own it, like the Remove Ads product for the app I was working on. The other main difference is when working with Amazon you have to worry about users. There can be multiple users using a single device and you have to take care of what products they own. There is a method callback with the current user ID.

The In-App purchasing library should not be added in the libs folder. It should be added in the Java Build Path as an external jar as the documentation suggest. To be continued....