Contents


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

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

Comments

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
    Screen capture of the Application in the Catalog

Step 2. Deploy the BlueList NodeJS application to Bluemix

  1. Clone the sample code to local and download Cloud Foundry CLI.
  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
    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
    Screen capture showing the application restarting

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
    Screen capture showing the bluelist.properties file

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
    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
    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
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
Screen capture of todos database showing the number of items synced to the database

The items are already synced to the database.

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

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!


Downloadable resources


Related topics


Comments

Sign in or register to add and subscribe to comments.

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