Windows Azure Mobile Services Now Supports Android

Windows Azure Mobile Services Now Supports Android

I have great news for people who develop applications for mobile devices. Windows Azure Mobile Services now officially support Android. Until now we only had support for Windows 8, Windows Phone 8 and iOS.
Windows Azure Mobile Services now support the most common operating systems for mobile devices. You can use the same Mobile Service endpoint for different clients. This means that you can only have one Mobile Service that can be used by a Windows Phone 8, an iOS , Windows 8 and Android application at the same time.

If it is the first time when you hear about Mobile Services you should know that it is a service that provides support for the creation of your application’s backend. Storage, tables, authentications, custom scripts, batch operation and many more features are supported by default. This means that you can focus on your client application without worrying about the backend. Everything is exposed as a REST API and can be accessed directly using the client SDK’s REST API (Windows 8, Windows Phone 8, iOS and Android).

When you create a new mobile service, you will be able to download a project that is already set up for your client. Different projects can be downloaded depending on your client (Windows 8, Windows Phone 8, iOS or Android). This means that you can start using and integrating Mobile Services without losing time on setup.

One thing that I really enjoy about Mobile Services is the SDK support for different environments. Even if Mobile Services endpoints can be accessed using REST calls, the Azure team created SDKs for each environment. In this case, we have an Android SDK that can be downloaded from here.

The first step to be able to use Mobile Services is to create a “MobileServiceClient” instance. This will be used to access all the services available on Mobile Services. When you create a new instance of this class, you will need to specify the url of your mobile service and the application key. All this information is available on the Windows Azure portal or on the default application that can be downloaded when you create a new Mobile Service. Warning, don’t share your application key – anybody can access your services if they have the key.

MobileServiceClient mobileClient = new MobileServiceClient(“mobileSericeUrl”,”applicationKey”,this);

If you want to access a specific table from the backend you can use the “getTable” method. The only thing that you need to know is the name of table: = mobileClient.getTable(“myTable”);
This table supports all the CRUD operations (insert, update, delete and select). In the next example we can see how you can select the rows from a table that have a column equal to a specific value:

myTable.where().field(“name”).eq(“tom”)

.execute(new TableQueryCallback<MyItem>() {

public void onCompleted(List<MyItem> result, int count, Exception exception, ServiceFilterResponse response) {

// custom code

}

});

As we can see, it is pretty simple to access any kind of Mobile Service resources. We can define custom scripts on the backend which can run before a CRUD operation is executed on the tables. These custom scripts are defined in JavaScript.
The user authentication is already supported. Different identities such as Google, Facebook, Microsoft accounts, Twitter are supported. Before using them we need to configure the identity provider on the backend. It’s easy to do, we only need to add the key and secret key for each identify provider.  The Windows Azure team created a page where we can add this information.

After we are done with this configuration we can specify what kind of user has access to each CRUD operation over each table. When we want to request the user to login on the client, we need to call the MobileServiceClient login method and specify what kind of identity we want to use.

mobileClient.login(MobileServiceAuthenticationProvider.Google, new UserAuthenticationCallback() {

new UserAuthenticationCallback() {



}

});

From the moment when a user is authenticated, the user information will be sent every time when a request is made to Mobile Services. What I liked when Mobile Services was launched was the support for push notifications not only for Windows 8 and Windows Phone 8, but also for iOS. Of course we also have support for Android applications. You will need to use Google APIs to push data in order to be able to use push notifications on Android devices.

After you create an account, you will need to enter the API key in the push tab of the Mobile Services portal. You can use your Google APIs on the client application as you normally do. You will be able to send push notifications from different locations using the Mobile Services backend. For example we can send a push notification to our client when someone inserts an item into the table.

<div>

function insert(item, user, request) {

request.execute({

success: function() {

request.respond();

push.gcm.send(item.channel, “New data available”, {

success: function(response) {

// …

}, error: function(error) {

// …

}

});

}

});

}

</div>

As we can see, we can now create Android applications that use Windows Azure Mobile Services very easily. From now, when we need to create a backend for a mobile application that has support for different platforms we should really consider Windows Azure Mobile Services.

Tags: , , ,

You can be the first one to comment on this story.

Leave a Reply

Your email address will not be published. Required fields are marked *