Build an Android app using Cloudant NoSQL DB and Push Notifications on Bluemix

Store, delete, update, and query objects stored in the cloud

03 May 2016
PDF (1192 KB)
Share:
author photo - belinda vennam

Belinda Vennam

Software Engineer, IBM Mobile Cloud Services

dW Connections

author photo - nick gibson

Nick Gibson

Software Engineer, IBM Mobile Cloud Services

dW Connections

author photo - andrew huffman

Andrew Huffman

Software Engineer, IBM Mobile Cloud Services

dW Connections

author photo

Chris Shen

Product Manager, IBM Bluemix Dev. Advocate

LinkedIn

Editor's note: This tutorial is an update to "Build an Android app using the IBM Mobile Data for Bluemix cloud service" originally published in February 2014. It was written using the Bluemix classic interface. Given the rapid evolution of technology, some steps and illustrations may have changed.

You may already know about some of the benefits of Bluemix, IBM's open platform for developing and deploying mobile and web applications. The many pre-built services in the mobile solutions in IBM® Bluemix™ make it easy for developers to build and enhance applications.

Tutorials in this series show you how to add cloud-based services to your apps. In this tutorial, we'll cover the steps to build an Android application using the IBM Cloudant NoSQL DB service on Bluemix.

Have you ever gone to the grocery store and forgotten the exact ingredient your spouse needed for that fabulous soufflé recipe? Or the lunch box dessert the kids had requested for the next day? What if they all could enter their requests into a shared grocery list, and you could receive push notifications alerting you to the updates?

Enter the BlueList application. It’s a simple app that uses Bluemix services and will get you started writing your own (more complex) apps in no time! This tutorial shows you how to start with an Android application and add the Cloudant NoSQL DB service to store, delete, update, and query objects stored on the cloud. (A future tutorial will show you how to add the Push and Node.js Cloud services to your application so you can get notifications when the grocery list is updated, and so the list can be refreshed on all devices when one of the devices updates the list in some way.)

This simple app uses Bluemix services and will get you started writing your own (more complex) apps in no time.

Note: The sample code has been deprecated and is no longer supported.

What you'll need for your application

 
  • Familiarity with Android development
  • An Android development environment. We used Eclipse with ADT, but feel free to use your preference
  • The Bluelist sample code (click the button above) that includes the front-end and back-end code used in this tutorial.
  • A Bluemix account to use the Bluemix services

Step 1. Create a Mobile Cloud application on Bluemix

 
  1. Log in to Bluemix.
  2. Click MobileFirst Services Starter under Boilerplates in the Bluemix catalog.
  3. To create an app, enter an app name, host name, and domain (use the defaults for the other options). Click Create.
  4. After you create the application and it has finished staging, it appears in your console. Click your new application to go to its overview page. You will find a Node.js runtime as well as other services running on Bluemix. Screen capture of the Application in the Catalog

    Click to see larger image

Step 2. Deploy the BlueList NodeJS application to Bluemix

 
  1. Clone the sample code to local and download Cloud Foundry CLI.

    Click to see larger image

  2. Open your local folder where you cloned the sample code. The bluelist folder has the front-end code and the NodeJS folder has the backend code.
  3. Open the NodeJS folder and update the manifest.yml file according to the Bluemix app and host names that you just created. In this example, my Bluemix app name is shenyBluelist: Screen capture of the manifest.yml file showing the applications that are running
  4. Run the following cf commands to update the manifest.yml file on Bluemix and restart the application.
    cf api https://api.ng.bluemix.net
    cf login
    cf apps
    cf push -f manifest.yml
    Screen capture showing the application restarting

    Click to see larger image

Step 3. Configure the front-end in the Bluelist sample

 
  1. Download Android Studio.
  2. Open the front-end project folder, bluelist in Android Studio.
  3. Update the bluelist.properties file located under the assets folder with your Bluemix application information. You can find the route and APPID information by clicking MOBILE OPTIONS on your Bluemix application overview page. Screen capture showing the bluelist.properties file

    Click to see larger image

Step 4. Configure the back-end in the Bluelist sample

 
  1. Open the Mobile Client Access service for your Bluemix application. Choose Customer Configure (you can also choose Facebook authorization and Google authorization) to configure authentication. Screen capture of custom and facebook authentication windows
  2. Click Edit. Use customAuthRealm_1 for the Realm name and your Bluemix application route for the URL. Save your configuration. (The User Yotem with password 456 is hard coded into the sample and will authenticate automatically.) Screen capture of the custom authentication fields

Step 5. Run the mobile app

 

Build your Android App and run it on your Android device or simulator. Add some items to the To Do List of your app. Remember to pull down the screen to sync the app with the database on the cloud.

Screen capture of the mobile app running on a mobile device

Step 6. Check your data on the cloud

 

In Bluemix, select the Cloudant NoSQL DB service and click the Launch button to open the Cloudant dashboard.

Screen capture of the Clouding NoSQL DB service page

Go to the todosdb database.

Screen capture of todos database showing the number of items synced to the database

Click to see larger image

The items are already synced to the database.

Screen capture showing your Google API Project number and Google Cloud Message API Key

Click to see larger image

Conclusion

 

Developing this app using the Cloudant NoSQL DB service should give you a sense of how easy it is to consume and integrate mobile data capabilities using Bluemix!


BLUEMIX SERVICE USED IN THIS TUTORIAL:The Cloudant NoSQL DB service provides access to a fully managed NoSQL JSON data layer that's always on.

RELATED TOPIC:Next: Add the Push and Node.js Cloud services

Add a comment

Note: HTML elements are not supported within comments.


1000 characters left

developerWorks: Sign in

Required fields are indicated with an asterisk (*).


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Information in your profile (your name, country/region, and company name) is displayed to the public and will accompany any content you post, unless you opt to hide your company name. You may update your IBM account at any time.

All information submitted is secure.

Choose your display name



The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

Required fields are indicated with an asterisk (*).

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


All information submitted is secure.

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Mobile development, Cloud computing
ArticleID=963125
ArticleTitle=Build an Android app using Cloudant NoSQL DB and Push Notifications on Bluemix
publish-date=05032016