Using push and Cloudcode services to build an Android application

Source: Internet
Author: User
Keywords Applications Push cloudcode
This article contains a demo, sample code, and complete instructions for creating a bluelist Android application. You can apply the knowledge you have learned to integrate Mobiledata, Cloudcode, and Push services into your own applications.

Codehttp://www.aliyun.com/zixun/aggregation/11696.html ">name:bluemix is a beta-grade product that will continue to improve as we continue to make it more functional and easier to use." We'll do everything we can to keep this article up to date, but not always. Thank you for your understanding!

You may have learned some of the benefits of Codename:bluemix, an open platform for IBM to develop and deploy mobile and WEB applications. Many of the pre-built services in Bluemix make building and enhancing applications easier.

In this article, we will use the Push service to extend an Android application. Other articles in this series describe how to add more cloud-based services to your application.

As the previous article has already described, the Bluelist application is a simple Android application. This article adds a Push and Cloudcode service to the Bluelist application so that when a device updates a list in some way, the list is updated on all devices.

In the last article, we added the Mobiledata service, and we persisted with the items in a list. Now we will add push notifications and Cloudcode to be notified when the list is updated. If you do not read the previous article in this series, you can start with V1 code, but you need to perform a Catch up task before you can perform the steps required to add a Push and Cloudcode service. If you've finished reading the previous article, you can now start with the existing code and perform the following steps to add the Push and Cloudcode services. If you want to download and use the V2 code directly, you need to perform some steps to make the Bluelist application that contains the Mobiledata, Push, and Cloudcode services work correctly. The V2 code contains changes to the V1 code in this article.

Prerequisites for completing your application

Reading the previous article, we added the Mobiledata service to the Android application in our last article. This application is the starting point for this article.

familiar with Android development.

An Android development environment. We use Eclipse with ADT, but you can also use your favorite development environment.

Familiar with git used to download v1 and Cloudcode from Jazzhub.

The V1 code on the Jazzhub (click the button above) or the existing code in the previous article.

The Cloudcode module on the Jazzhub. Download this module, which contains a package.zip, Package.json, and Itemlist.js.

A GCM Sender ID and API key from Google. Find out how to obtain this key in Google's instructions or our instructions.

Note: You need a Gmail account to perform this task.

Supplementary task: If you skip the previous article

Download the V1 code from Jazzhub if the code has not been downloaded.

See step 1th in the previous article. Create a Mobile App Services package on Bluemix.

Perform step 1.1-1.10 with one exception: Do not delete the extra lines in the Configuration.json file this time.

Perform these steps, log on to the Bluemix and create an application (bluelist), download the Android SDK, update the Configuration.json file with your API key, and add Ibmcore.jar to your libs directory Ibmdata.jar.

It is high time to run this code in the emulator to verify your Android development environment before adding a Push service. You should be able to perform the 7th step of the previous article. Run the application and step 8th. View the data in the cloud.

If your application runs successfully, you are catching up on the progress and can add Push and Cloudcode services!

Before you begin: Get your GCM Sender ID and the JAR file required for Push

Get your project number and GCM API key

Open the Google developers Console.

Click Create Project, enter a name for the project, click Create.

Copy the item number from the top of the page. This is your GCM Sender Id (Google API Project number) and will need that information later!

Click the APIs & Auth on the left side of the page.

Open Google Cloud HTC for Android.

Under APIs & Auth, click Credentials.

Click the CREATE NEW KEY under the Public API Access section.

Click Server Key.

Click Create.

Copy the API key from the Public API Access section. This is your GCM Sender Auth Token (GCM API Key). You will need this information later!

Add Gcm.jar to your project

Open Eclipse, select Window > Android SDK Manager.

Select the Show:obsolete check box at the bottom of the window.

Scroll to the bottom and select Google Cloud HTC for the Android Library.

Click Install 1 Package and accept the license.

Find <android_sdk_location>\extras\google\gcm\gcm-client\dist in your file explorer

Copy the Gcm.jar file to the Libs directory of your project.

Add Ibmcloudcode.jar and Ibmpush.jar to your project

Find the Android SDK you downloaded in the previous article in step 1.7.

Copy the Ibmcloudcode.jar and Ibmpush.jar files to the Libs directory of your project. The following 5 jar files should now be included in the Libs library:

1th step. Add GCM API Key to your application in Bluemix

Log in to Bluemix.

Let's say you've completed the steps in the previous article or the task steps that you added above to click your application in DASHBOARD view.

Click the Push service Your_app_name:push.

Under the Revisit tab of the Push service, click EDIT under Google Cloud HTC.

Fill in the GCM API Key and Google API Project number that you obtained from Google, click SAVE.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.