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....

Friday, December 6, 2013

Color Mania Spree - Released

Color Mania Spree
Over the last 2-3 months me and +Кире Серафимов have been working on a Brain and Puzzle game for Android called Color Mania Spree.

You are presented with a black and white picture and a color palette. The goal of the game is to guess the missing colors from the image. There are 125 images in the game from different categories like logos from brands, country flags, games, cartoons etc. The images are grouped in 12 levels with 10-20 images each. There is a bonus level called Spree with all 125 images appearing in random order.
The game includes Leaderboards and Achievements powered by Play Game Services so you can compete with your friends.

Over the last 4 week the game was in beta while we tested the functionalists and implemented new ones. We want to thank all the beta testers who helped us improve the game.

On December 2 we finally published the game on the Google Play Store. In the meantime we released 4 new versions with improvements and small bug fixes.

The game is free with in-app purchase to remove the ads. You can also buy hints and rubies but you can enjoy the game without spending a single $.

For the first 1000 people who download the game we want to offer the in-app purchase for ads removal (worth $2) for free via promo code. All you have to do is download the game from the Play Store, click on Hints, click on Promo Code and enter the promo code CMSPREE. The ads will be removed the next time you start the app.

If you have any suggestions, comments for the game please leave a comment below.
Rating the game on Google Play would be really helpful.

Thursday, November 7, 2013

I'm making a game - Color Mania Spree

I'm working on a game for Android together with +Кире Серафимов.
The name of the game is Color Mania Spree.

You are presented with a black and white picture and a color palette. The goal of the game is to guess the missing colors from the image.

There are 125 images in the game from different categories like logos from brands, country flags, games, cartoons etc. The images are grouped in 12 levels with 10-20 images each. There is a bonus level called Spree with all 125 images appearing in random order.

Color Mania Spree
The game will use Google Play Services for achievements and leader-boards.

At the moment we are most of the game logic is done and the game is in beta. There are some bugs with the game-play, the tablet layout isn't finished, achievements and leader-boards are not yet implemented.

We are looking for beta testers to test the game trough Google Play.If you are interested drop me a message on Google+.

Thursday, October 31, 2013

Android and Facebook sharing


Recently I worked on a freelancing project for Android. It was a port of an app/game from iOS to Android. The app included sharing with Facebook, Twitter, SMS and email. This the story about and android developer trying to do a simple thing (share on Facebook) the hard way.

The problem

Sharing on Android is simple, it's 5 lines of code:
But that's just in theory, in practice it's a little different. The problem: Facebook.
Facebook shows in the list for the ACTION_SEND intent but it ignores the text sent as EXTRA_TEXT.
StackOverflow is full with topic about the broken Facebook share on Android:
There is even a bug reported on Facebook developers but the status of the problem is "By Design". They are not fixing it any time soon.

After a round of swearing at Zuck I started looking for a solution on Google and I found a blog post with an elegant solution (it's actually a hack).
The idea is simple:

  1. Create your intent
  2. Query the Android PackageManager for apps that support the intent
  3. Manually create the Share dialog using AlertDialog
  4. When the user selects an app
    1. If the app is Facebook - Share using the Facebook SDK
    2. If it's any other app let Android handle the sharing
More details and code example on the link above.

Integrating the FacebookSDK for Android

I started with visiting the website, I registered as a developer, downloaded the FacebookSDK and started reading the Getting Started guide.

Basically you have to download the SDK, import it into Eclipse, and reference it as a library project for your app. Then you have to create a Facebook app in your Facebook developer console, and add a Native Android application to your Facebook app. It's simple you just enter your package name, the full activity name (where you do your Facebook authentication) and a keyhash. You can enter more than one keyhash (ex. one with your debug key and one with your release key). There is a nice command in the guide for getting the key, it's a simple command you write in the terminal. 
Don't do that. I tried with two keys (debug and release) and it gave me a wrong key hash twice. Use the second method (under troubleshooting). Alter the onCreate method and add:
It's the safer option.

To login with Facebook you just need to call one method, implement the callback and add on line of code to the onActivityResult method on your activity.

Sharing a status update What I tried first

First I tried using the Request class and the newStatusUpdateRequest method. It didn't work.

What worked

To post a status update first you need the publish_stream permission. You can find the code for asking the user for permission and publishing to the feed here.

Finishing toughts

I'm not sure why Facebook chose to handle the share intent but ignore the text. The should either do things right - handle the intent and text or not show in the list when we chose ACTION_SEND.
Another question is why are they a TOP DEVELOPER on the Play Store when the can't (or won't) handle a simple ACTION_SEND intent.