Analytics for Mixed Reality

Behind every good user experience is great analytics

If you ever designed or developed client side applications or websites you’ve probably integrated with an analytics service to provide telemetry data to help make informed design choices and development decisions to improve user experience and business outcomes.
One of the key performance indicators is when you track steps or funnel operations as conversions to calculate a conversion rate for each session. You would want to know how the conversion rate can be improved upon and a good idea would be to watch out for the steps with a high bounce rate where users are dropping off. If the bounce rate is very high then there might even be a blocker or flaw in regards to the user. Either way we can understand the benefit for the collection and study of analytics which is essential for providing the insights that will help designers and developers craft better user experiences and advance product development.

Application Insights for Unity

If you’re a Unity developer or you develop in VR, AR, MR or XR you might have stuck the issue of gathering analytics onto the backlog but it should be one of the first items done so you can use it to help plan and prioritize the other features. To help you get started I’ve made an Application Insights for Unity sample so you can start logging telemetry in just a few minutes! All you have to do to add this to your existing Unity app or game is drop the Unity Application Insights script onto a Game Object, add your Application Insights Instrumentation key and you will be all set to record valuable user session telemetry automatically. After that all you have to do it wait around 5 mins for the telemetry to display in the Application Insights Usage section in Azure. You can also extend this in you own app or game to record any custom events or metrics you want to know about. But right out of the box (without any additional effort on your part) you will be able to visualize telemetry for users, sessions and user flow and their journey across the scenes of your Unity app or game. Here are just some of the visualizations already built-in to Application Insights in the Azure portal:

User Flows

Chart user flow across Unity scene changes and split by custom or interaction events.

Unity App Insights User Flow


View users and events during sessions.

Unity App Insights User sessions


Create funnels by creating step by step conditions to get conversion rates.

Unity App Insights Conversions


Review returning users over a period of time.

Unity App Insights Retention

Analytics for Mixed Reality interactions

In the Unity project there is also a MR sample to show how to setup Application Insights for recording custom interaction events and metrics in a scene. To use the sample please fork or clone the Unity Application Insights sample project, import the plugins and setup Application Insights in Azure portal if you haven’t already. Once you’ve got that you can get up and running on HoloLens straight from the Unity Editor:

  1. To view the Mixed Reality sample in HoloLens open the scene named “Scene-MR”. (Make sure you’ve pasted in your Instrumentation key into the Application Insights game object script)
  2. Connect to remote HoloLens device using Window > XR > Holographic Emulation window. Note: Requires the Holographic Remoting Player installed and open on HoloLens to get the Remote Machine IP address.
  3. Hit Play and you will start recording interaction telemetry with the holograms.

The Application Insights MR scripts will record taps, gaze time and object proximity – when users physically “visit” a hologram by moving closer to it.
You can also create your own custom dashboard templates using Ibex Dashboard (which is another project I helped with) and is designed for visualizing data from Application Insights using Kusto queries.

You can add the dashboard template for MR shown above to visualize the telemetry for MR custom events and metrics. Check out the readme on github for more info about installing custom Ibex Dashboard templates.

Querying Application Insights for data visualisation

Ibex dashboard is an open source web app for displaying telemetry data from Application Insights. It comes with a number of sample templates including analytics dashboards for Bots. If you’re developing a bot and you want to see how your bot is performing over time then you can select the Bot Instrumentation template which requires you to enter your Application Insights App Id and App Key. Also depending on your bot you will need to add Node.js instrumentation or C# instrumentation in order to enable logging to Application Insights. Then after a couple of minutes you will start to see the data come through! The dashboard can be completely customised using generic components including charts, tables, score cards and drill-down dialogs. These elements can be used to review how your bot performs over time, monitor usage stats, message sentiment, user retention and inspect user intents.

If you are new to Application Insights one of the useful features of the Ibex dashboard is the ability to inspect an element’s Application Insights query and the formatted JSON data side by side. 

This query can be copied and played back inside your Application Insights live code editor. This is a good way to learn how the Application Insights queries work as you can step through the query by commenting out various lines with double slashes ‘//’.

Writing Azure Log Analytics queries for Ibex dashboard

The Ibex dashboard schema is composed of meta data, data sources, filters, elements and dialogs. Each data source allows you to define a query and a ‘calculated’ javascript function to process the query’s results for display purposes. Before learning to write Application Insights queries I was used to writing javascript map / reduce functions to aggregate data and so it’s all too easy to rely on previous javascript knowledge to process the data from a basic query. But often this javascript ‘reduce’ aggregation logic can done in an Application Insights query with a lot less effort. So invest some time up front to learn the key Application Insights query concepts and it will pay off in the long run!

To help to illustrate this we can look at the Application Insights query for tracking a bot to human hand-off during a user’s conversation session. For this scenario we built a QnA bot with the hand-off module installed. If a customer asks the QnA bot a question and no answer was found in the knowledge base we trigger an automatic hand-off to human. We want to show the fastest, longest and average times for customer waiting for an human agent to respond in the dashboard.

We can start by writing a basic query in Application Insights to get all the transcripts from the ‘customEvents’ table and ‘project’ only the information we need.

But in this example we are not using Application Insights to aggregate the results so we end up with a lot of results to process. Given the query above the following code snippet is the amount of Javascript required.

The first ‘reduce’ block is required to group the transcripts per user Id. Then for every user we track the state change from waiting and talking to human agent and calculate the time difference in seconds. Where ‘state’ is an integer value that marks the current status of the conversion.

0 = Bot
1 = Waiting
2 = Human agent

But we can optimise the code by doing the aggregation within the Application Insights query by using the ‘summarize’ operator and ‘count’ function.

Notice how you can apply aggregations in multiple passes, in this case the ‘summarize’ operator and ‘count’ function is used to aggregate results twice in conjunction with multiple ‘where’ statements that are used to filter the results. Now the javascript ‘calculated’ function code can be greatly simplified:

The only thing we do is a ‘reduce’ function to convert the time format ‘hh:mm:ss’ returned from the Application Insights query into a number of seconds for the various calculations for displaying in a score card element.

The final Application Insights query is available in the hand-off to human dashboard template and is included with Ibex dashboard.

Further reading and resources:

Unity3d and Azure Blob Storage

Previously I’ve looked at using Azure App Services for Unity, which provided a backend for Unity applications or games using Easy Tables and Easy APIs. But what if I wanted to lift and shift heavier data such as audio files, image files, or Unity Asset Bundles binaries? For storing these types of files, I would be better using Azure Blob storage. Recently I created an Azure Blob storage demo project in Unity to show how to save and load these various asset types in Unity. One of the exciting new applications for Unity is developing VR, AR or MR experiences for HoloLens where a backend could serve media content dynamically whether it’s images, audio, or prefabs with models, materials and referenced scripts. When thinking of cloud gaming the tendency is to consider it in terms of end user scenarios like massive multiplayer online games. While Azure is designed to scale, it is also helpful to use during early stage development and testing. There is an opportunity to create productive cloud tools for artists, designers and developers especially when extensive hardware testing is required in Virtual Reality, Augmented Reality or Mixed Reality development. For example, imagine being able to see and test updates on the hardware without having to rebuild the binaries in Unity or Visual Studio each time. There are many more use cases than I’ve mentioned here like offering user generated downloadable content for extending your game or app.

I’ll be covering the load and save code snippets from the Unity and Azure Blob storage demo commentary which you can watch to see how you can save and load image textures, audio clips as .wav files, and Asset Bundles. The Unity Asset Bundle demo will also include loading Prefabs and dynamically adding them into a Unity Scene using XML or JSON data which should give you some ideas of how you might like to use Blob storage in your Unity development or end user scenario.

Setup Azure Blob Storage

Setting up Blob Storage for the Unity demo can be done quickly in just a couple of steps:

  1. Sign in to your Azure portal and create a new Storage Account.
  2. Once the Storage account is provisioned then select the add new container button which will be used for storing the blobs.
  3. 02-CreateContainer
  4. Create the ‘Blob‘ type container which permits public read access for the purposes of this demo.
  5. 03-NewContainer-BlobAccess

Audio files

Saving Unity Audio Clips into Blob Storage

For the Unity audio blob demo I created a helper script to convert Unity Audio Clip recording to .wav files for the purpose of saving to Azure Blob Storage.
Once the audio has been recorded in Unity I can upload the file using the PutAudioAudio method which takes a callback function, the wav bytes, the container resource path, the filename and the file’s mime type. By the way this method must be wrapped using StartCoroutine which is the way Unity 5 handles asynchronous requests. Once the request is completed it will trigger the PutAudioCompleted callback function I have provided my script with a response object. If the response is successful you will see the wav file blob added in your Blob Container.

☞ Tip: Grab the Storage Explorer app for viewing all the blobs!

Loading .wav files from Blob Storage

As we used the Blob type container with public read access you can use the UnityWebRequest.GetAudioClip method to directly load the .wav file from Azure Blob Storage and handle it as a native Unity AudioClip type for playback.

Image files

For the Unity image blob demo I used Unity’s Application.CaptureScreenshot method to generate a png image representation of the current state of the game screen.

Saving Images into Blob Storage

The image is saved using the PutImageBlob method which is similar to the audio blob except we pass the image bytes and mime type.

Loading Image Textures from Blob Storage

As we used the Blob type container with public read access you can use the UnityWebRequest.GetTexture method to directly load the .png file from Azure Blob Storage and handle it as a native Unity Texture type for use. As I want to use the Texture in Unity UI to display as an Image I need to convert it to a sprite using my ChangeImage function.

Unity Asset Bundles

Unity Asset Bundles provide a way to dynamically load in assets in your project. This Asset Bundle demo for Blob Storage is a little more complicated than the other examples. An important note to remember is that Asset Bundle binaries need to be build for each target platform. Refer to Unity documentation on building Asset Bundles for more info on building Asset Bundles. Also make sure to review the code stripping section if you want to be able to use referenced scripts in your Prefabs when you do a build.

Building and uploading the Asset Bundles for each platform to Blob Storage

I have included the Editor scripts with the demo to build the Asset Bundle for each platform. NB: Windows 10 Store App (or HoloLens) bundles can only be built on the Windows Unity Editor at time of writing this. Building the Asset Bundles and uploading them is performed inside Unity Editor:

  1. Select Assets > Build Asset Bundles
  2. Select Window > Upload Asset Bundles…

Loading Asset Bundles from Blob Storage

If you like the Azure Storage Services library for Unity let me know about it on Twitter. Any issues, features or blob storage demo requests please create it as an issue on github for others to learn from and collaborate.

Azure App Services for Unity3D

Azure Mobile Services will be migrated to App Services on Sept 1st 2016. To prepare for this migration I’ve renamed and updated the open source Mobile Service Unity3d projects to support Azure App Service going forward.

Using Azure App Services to create highscores leaderboard for Unity

To demonstrate the Azure App Service I have created a sample Highscores demo for Unity to insert, update and query a user’s highscores. But to run the project in Unity Editor you will need to hook it up to an Azure App Service. Using an Azure account simply create a new App Service in the Azure portal, (for this demo I am using an App Service with Javascript backend). In a couple of minutes the Azure App Service should be up and running and ready to configure.

  1. Open Settings, search for Easy Tables and add a ‘Highscores’ table.

  2. Set all table permissions to allow anonymous access to start with.

  3. Manage schema to add Number column for ‘score’ and String column for ‘userId’

  4. Additionally, if you want to store user data or game scores you can enable authentication using Facebook, Twitter, Microsoft account or Google account. If you want to use the Facebook login in this demo you will need to create a Facebook app. Once you’ve created the Facebook app add the Facebook App ID and Secret to your Azure App Service Facebook Authentication settings.


    Then configure the Facebook App Basic and Advanced settings with your Azure App Service URL:


    If in doubt how to configure these settings check out the Azure App Service documentation.

  5. Once authentication is setup the ‘Highscores’ table script can be edited to save ‘userId’ information.


  6. In addition to table scripts you can also create custom APIs. In Settings, search for Easy APIs and add an example ‘hello’ API.


Once you have setup Azure App Service you can update the Unity scene with your App Service ‘https’ url and hit run!

Azure Mobile Services for Unity3d

State of play

If you’ve followed my previous Unity3D Azure tutorials I’ve covered two well known Unity Azure plugins – Prime31 and Bitrave. Bitrave had better multi-platform support, however it required the ‘JSON.NET’ paid asset to support iOS and Android. But then there was issues with iOS AOT compiler. Because of this I decided to start a new Azure Mobile Services library for Unity3d to support multi-platforms like Unity3d – iOS, Android and Windows without need for paid plugins.

Using Azure Mobile Services in Unity3d

You can drop the Unity3dAzure library into your existing Unity project or try out the demo project to get started.

Getting started

  1. Download the Unity3d Azure demo project or use git to clone the project:
  2. Create a Mobile Service
    • Create ‘Highscores’ table for app data
    • Modify ‘Highscores’ table Insert node script to save userId
    • Create a custom API called ‘hello’
  3. In Unity3d open scene Scenes/HighscoresDemo.unity
    • Check the Demo UI script is attached to the Camera. (The script can be attached by dragging & dropping the Scripts/HighscoresDemoUI.cs script unto the Scene’s ‘Main Camera’ in the Hierarchy panel.)
  4. Paste Azure Mobile Service app’s connection strings into Unity Editor Inspector fields (or else directly into script Scripts/HighscoresDemoUI.cs)
    • Mobile Service URL
    • Mobile Service Application Key
  5. If you want to save score with userId then create Facebook app
    • Fill in Azure Mobile Service’s Identity > Facebook settings (App Id & App Secret)
    • Paste Facebook access user token into Unity Editor Inspector field (or else directly into Scripts/HighscoresDemoUI.cs)
      Play in UnityEditor


Special thanks to Jason Fox and Bret Bentzinger who put together the UnityRestClient library using the JsonFX plugin.

Using Azure CLI on Mac OS X to create Mobile Service

One of our startups at MS Ventures was looking to use the command line to manage their Azure account on Mac. If you prefer using Mac OS X Terminal or iTerm and have an Azure account then you should check out the Azure CLI tools for Mac.

Azure CLI

Install Azure CLI for Mac

You can either download the Azure Command Line tools installer for Mac or install the Azure command line tools using nodejs. I have previously written a post covering installing nodejs using NVM.

Test Azure command works with help:

Download Azure Publish Settings file

Sign in to your Azure account and download your *.publishsettings subscription file.

Import Publish Settings file

Import path to downloaded Azure Publish Settings file:

Tip: You can drag & drop the file into Terminal instead of typing the link.

Show Azure account subscriptions:

Create Mobile Service with Azure CLI

Create Mobile Service TerminalTest:

You will be prompted to enter SQL admin user name and password. The Mobile Service should only take a couple of minutes to provision.

Show Mobile Service details including applicationUrl and applicationKey:

You will want to make a note of your applicationUrl and applicationKey for CRUD examples below.

Create Table Items:

Show Tables:

Read Table Items:

CRUD examples with Mobile Service using curl

You can quickly execute Create, Read, Update and Delete operations with Mobile Services using curl commands. Here’s a quick overview of Mobile Service CRUD operations and methods:

Operation Method REST URL format
Create / Insert POST https://<service_name><table_name>
Read / Query GET https://<service_name><table_name>
Update PATCH https://<service_name><table_name>/<item_id>
Delete DELETE https://<service_name><table_name>/<item_id>

You will need to replace the X-ZUMO-APPLICATION header value below with your own Mobile Service applicationKey.

  1. Create / Insert

    Change the data text to submit a couple of items… Note you will get a JSON response with the id of the inserted item. This item id value is to be used in the Update and Delete examples below.

  2. Read / Query

  3. Update

    ^ Data updates shown in Azure Mobile Service table.
  4. Delete

How to query and filter Mobile Service table data with curl

Get items marked as complete

Get items starting with text ‘hello’ with total count of results:

Get a collection of items in order (eg. pagination):

Just be aware if you use double quotes for --location then you must escape the dollar signs that prefix the params with a backslash (eg. \$). Single quotes don’t require dollar escaping but you may have trouble encapsulating filters with quoted strings hence I have opted for double quotes in these query examples.

Unity3D Leaderboard demo using BitRave Azure plugin

This is a quick Unity3D game developer tutorial showing how to save, update and query high scores stored in the Cloud using a Mobile Service and the BitRave Azure plugin.

Watch how to create a Leaderboard in the cloud using the Unity3D BitRave plugin.

  1. To save scores in the Leaderboard table you will need to create a Mobile Service.

    If you don’t have an Azure account there is a special Cloud GameDev Offer for game developers.

  2. Get the BitRave plugin with Leaderboard scripts on my GitHub fork.

    There are two new scripts I’ve added for the Leaderboard demo:

    Unity3D BitRave Fork with Leaderboard script demo
  3. Create new Unity project.

    Unity3D BitRave Fork with Leaderboard script demo
  4. Copy contents of the BitRave Universal Plugin Assets folder into your Unity3D project’s Assets folder.

    Unity3D BitRave Fork with Leaderboard script demo
  5. Import JSON.NET dependancy from Unity Asset Store.

    Unity3D BitRave Fork with Leaderboard script demo
  6. Open the TestAzure scene.

    Unity3D BitRave Fork with Leaderboard script demo

    Select Main Camera and remove Script in the Inspector panel. (This will be replaced later.)

    Unity3D BitRave Fork with Leaderboard script demo
  7. Create ‘Leaderboard’ table in Azure Mobile Services.

    Unity3D BitRave Fork with Leaderboard script demo
  8. Open AzureUILeaderboard.cs script and replace Azure Mobile Service connection strings.

    Unity3D BitRave Fork with Leaderboard script demo
  9. Drag & drop AzureUILeaderboard.cs script to attach it to the Main Camera.

    Unity3D BitRave Fork with Leaderboard script demo
  10. Now you’re ready to play in Unity Editor add post some high scores!

    Unity3D BitRave Fork with Leaderboard script demo
    Unity3D BitRave Fork with Leaderboard script demo

In this demo project you can submit new scores, return list of all scores and update them. You can also query to show only high scores or get list of a user’s scores.

Check it out!

Karma Labs on Azure Mobile Services and BitRave plugin in their Unity3D game development.

If you are also looking to handle user identity with Mobile Services and configure build settings for iOS and Android development I touch on this in my first getting started with BitRave Azure plugin tutorial.

Share your Unity3D #GameDev with @deadlyfingers

Unity3D game dev with Azure Mobile Services using BitRave plugin

This quick-start tutorial is for Unity3D game developers who would like to get a cloud backend that runs across multiple platforms (including the Unity Editor for quick testing). One of the big advantages for game devs using Unity3D is that it supports so many platforms. It’s fair to say more people own more than one device that connects to the internet and a lot of them can run apps and games. While the platforms and ecosystems may differ as a gamer I would like to play the same game across any device (and on any platform) and expect things to sync. Azure Mobile Services is a ‘Backend as a Service’ which supports multi-platform app development. In Unity the BitRave plugin for Azure Mobile Services is designed to just work on any platform that Unity supports.

Watch getting started with Unity BitRave Azure plugin running on iOS and Android

  1. To kick off with create a Mobile Service in Azure management portal. If you don’t have an Azure account yet game developers can register for the Cloud GameDev Offer.

    NB: A Mobile Service will only take a minute to setup and just a couple of minutes more to become active and ready to use.

  2. Download BitRave plugin.

  3. Create new Unity3D project.

  4. Copy BitRave’s AzureMobileServicesUniversalPlugin/Assets into Unity3D project’s ‘Assets’ folder.

  5. Get JSON.NET Unity asset to enable cross platform support.

  6. Open TestAzure Scene.

  7. Open AzureUI.cs script and replace the connection strings with your own Mobile Service URL & API Key.

  8. The BitRave demo uses Authentication with Facebook. You will need to create a Facebook app for your Mobile Service and copy & paste the App Id and App Secret into your Mobile Service’s IDENTITY Facebook section. Then generate the Facebook Access Token under Facebook’s Tools > Access Tokens.

    Copy the Access Token and paste into AzureUI.cs script’s Access Token value.

    NB: Remember to save changes.

  9. In Unity select the Main Camera and remove the Script in the Inspector panel.

    Reattach the AzureUI.cs script. (Drag & drop the script onto the Camera.)

  10. Add the demo TodoItem table (in Azure Mobile Service’s get started section).

  11. Run in Unity Editor and connect to Mobile Service.

    Once logged in you can add a TodoItem.

    You can query or list all items.

    Items can be selected to updated.

  12. In Unity Build Settings switch platform to build for iOS. I’ve selected Development Build and Symlink Unity Libraries for smaller/faster builds.

    To run on the iOS Simulator edit Player Settings and under Target iOS Version menu select Simulator SDK

  13. Open Xcode project to build & run. Rotate iOS simulator to landscape to display UI.

    Connect to Mobile Services by logging in to add some items.

  14. In Unity Build Settings switch platform to build for Android. I’ve selected Development Build and Google Android Project.

    Edit Player Settings to change the Bundle Identifier. (This is in reverse domain name notation – for example net.deadlyfingers.DemoApp)

  15. Import Android project into Android Studio.

    Edit the AndroidManifest.xml and change the installLocation attribute to auto.

    Build & run app. (I find the Nexus 7 tablet API 21 ARM emulator works best with Unity builds.)

    Rotate Android emulator to landscape to display UI.

    Connect to Mobile Services by logging in to add some items.

One more thing to todo!

You can also record the userId by adding one line of code on the server-side.


Edit TodoItem table Script > Insert

Score bonus points!

Check out my Leaderboard BitRave tutorial showing how to save, update and query high scores stored in the Cloud using a Mobile Service.

Share your Unity3D #GameDev with @deadlyfingers

Unity3D and Cloud backend using Azure Mobile Services and Prime31 plugin

Unity game developers looking to publish their games on Windows Store might want to add global/local high-score leaderboards, record user achievements and level progress. For example the ability to save level progress is usually important as users tend to own more than one device and won’t really like the idea of starting over again. With Azure Mobile Services it’s really easy to setup a cloud backend for apps so why not use an Azure Mobile Service to provide a backend for your game? The best part is it will only take a couple of minutes to setup!

Watch getting started with Unity Prime31 Azure plugin running on Windows

  1. Sign-in to Azure portal. If you don’t have an Azure account yet game developers can register for the Cloud GameDev Offer.
  2. Create Azure Mobile Service
    Create Mobile Service
    Create Mobile Service
    Create Mobile Service
  3. Create Demo TodoItem Table
    Create Mobile Service
  4. Get Prime31 “Microsoft Azure Plugin” for Windows 8 Store. (free until July 2015)
    Create Mobile Service

    When you click on the “Download Now” button, it will prompt you for your name/email. Submit the form to get the download link to the Unity plugin sent to your email.

  5. Download & install Microsoft Azure Mobile Services SDK.
    Install Azure Mobile Services SDK
  6. Create new Unity3D project
    Unity3D New Project
  7. Download Prime31 plugin from email link and then open the ‘MetroAzure.unitypackage’ package
    Open Prime31 plugin package
  8. Import the Prime31 plugin package.
    Unity3D import plugin package
  9. Open “MetroAzure” Scene
    Unity3D open MetroAzure Scene
  10. Open “MetroAzureDemoUI.cs” Script
    Unity3D open MetroAzureDemoUI script
  11. Copy & Paste Azure Mobile Services Connection Strings (from Azure Mobile Service portal)
    Unity3D open MetroAzureDemoUI script

    Remember to save changes!

  12. Select File > Build Settings and target Windows Store platform.
    Unity3D Build Settings
    • “Add Current” scene
    • Select “Windows Store” and “Switch Platform”
    • Select C# Solution and SDK “8.1”
  13. Select Player Settings
    Unity3D Player Settings

    Under “Metro Unprocessed Plugins” set:
    Size: 1
    Element 0: P31MetroAzure.dll
    Click Build

  14. Open Windows Store build in Visual Studio
    Windows Store build
  15. Open ‘Package.appxmanifest’ manifest to add Internet capabilities.
    Windows app manifest capabilities
  16. If necessary open ‘Configuration Manager’ to target current PC hardware.
    Windows Configuration Manager
    Windows Configuration Manager x86
  17. Build and run!
    Visual Studio
    Unity demo

    ‘Connect Azure Service’ first, then try adding some items.

    Azure Mobile Services Demo Table

    You will see the items appear in your Azure Mobile Service ‘TodoItem’ table.

Ready for the next level?

Check out these links which will show you how to make a leaderboard using Azure Mobile Services & Prime31:

Additional Resources:

One more thing…

Now is a great time to publish Unity games for Windows!

  • Lifetime dev centre means no more recurring annual developer fees!
  • Take advantage of the Unity Offer Program for Windows apps to qualify for developer device, Unity Asset Store Voucher, Unity3D Pro License, ID@XBox priority and more!

Share your Unity3D #GameDev with @deadlyfingers

Send GCM Push Notifications using Azure Mobile Services

  • Difficulty Rating***
  • Time Estimate15 minutes

Tutorial requirements:

  1. First install Google Play Services package in the Android SDK Manager.

    NB: If using an Android Virtual Device then ensure your Target is set to Google APIs to allow Push Notifications to work.

  2. Create a new project in Google Developers Console.

    Turn on Google Cloud Messaging for Android.

    Create a new Public API access key.

    Create a new Server key.

  3. Copy the public API key

    Paste API key into Mobile Service’s Push > Google Cloud Messaging settings

    Save changes.

  4. Copy google-play-services.jar (from Android SDK libs) and notifications.jar (from Azure Mobiles Services SDK for Android) into the Android project’s libs folder.

  5. Add Push Notification permissions to the project’s AndroidManifest.xml.

    NB: Replace all occurrences of **my_app_package** with the manifest’s package name attribute.

    Add the receiver block just before the application closing tag.
    eg. … </application>

    NB: Replace **my_app_package** with the manifest’s package name attribute.

    NB: If you get a red text error on receiver notifications.NotificationsBroadcastReceiver then add dependencies to the build.gradle file and sync project libraries.

  6. Copy Google Project Number in overview section.

    Paste value into as a String constant.

    In the onCreate method of add a Notifications Manager handler.

  7. Create a Channel class

  8. Create MyPushNotificationsHandler class

    Tip: To auto import classes in Android Studio enable Add umabiguous imports on the fly

  9. Create new Channel table in Azure Mobile Services.

  10. Edit TodoItem table Script > Insert

    This will send a push notification upon successful insert of a Todo item.

  11. Edit Channel table Script > Insert

    This will prevent duplicate registrations of user and device handles.

  12. In the app add a Todo item to trigger a Push Notification

    The Push Notification will appear with the Todo item text.

That’s all there is to it! If you wanted to take it to the next level you could use this backend Mobile Service and roll it out across other platforms like Windows Store, Windows Phone, iOS, or use cross platform tools like Xamerin or Phonegap.

For latest platform support, how to connect to other identities and push notification services check out the Azure online docs.