Monday, June 11, 2012

Appcelerator Cloud Push Notification in Android

This tutorial is based on Ti SDK 3.0.0, which is outdated. I have a new blog post based on Ti SDK 3.1.3GA using GCM.
What is Push Notification?
Push notification allows an app to notify you of new messages or events without the need to actually open the application, similar to how a text message will make a sound and pop up on your screen. This is a great way for apps to interact with us in the background, whether it be a game notifying us of some event occurring in our game world or simply the iPad's mail application beeping as a new message appears in our inbox. read more

Push Notification in Titanium Using Cloud Service
We can achieve Push Notification in Titanium using Appcelerator Cloud Service in 5 steps.
  1. Cloudpush Module Implementation
  2. Retrieve Device Token
  3. Cloud User Login
  4. Subscribe  a Channel
  5. Push Configuration
1)Cloudpush Module Implementation
Cloudpush provides methods for accessing Android push notifications from ACS using the MQTT protocol. require cloudpush in your app and add module in  your tiapp.xml

// add this line in tiapp.xml
<module platform="android">ti.cloudpush</module> 
// add this line in app.js
var CloudPush = require('ti.cloudpush'); 

2)Retrieve Device Token
You can Retrieve Device Token using below code
          success: function deviceTokenSuccess(e) {
              alert('Device Token: ' + e.deviceToken);
              deviceToken = e.deviceToken
          error: function deviceTokenError(e) {
              alert('Failed to register for push! ' + e.error);
3)Cloud User Login
Before subscribe for Push Notification, cloud user should logged in.
So create a test user in Appcelerator Cloud Console
My Apps -> Manage ACS ->  DEVELOPMENT ->  Users
and login with credential. Use below code for cloud user login

        login: 'push123',
        password: 'push123'
    }, function (e) {
        if (e.success) {
            alert("login success");
        } else {
            alert('Error: ' +((e.error && e.message) || JSON.stringify(e)));
4)Subscribe a Channel
Add following code for channel subscribtion

                 channel: 'alert', // "alert" is channel name
                 device_token: deviceToken,
                 type: 'android'
             }, function (e){
                 if (e.success) {
                    alert('Subscribed for Push Notification!');
                     alert('Error:' +((e.error && e.message) || JSON.stringify(e)));
5)Android Push Configuration
It is final step. In Appcelerator Cloud Console go to
My Apps -> Manage ACS -> DEVELOPMENT -> Settings/Android Push Configuration and enter the Application Package in the text box. Your pakage name should be similar to  Here xxx is company name and androidpush is Application name

Cool.., You have completed Android Push Notification setup(Here is the whole sample code). This time for testing, run the application in android device and click the button "Android Cloud Push Notification". You will get 3 alerts continuously.

Then go to My Apps -> Manage ACS -> DEVELOPMENT -> Push Notifications, here you can see "1 Android clients subscribed to push notifications"

It is time to send push notification, enter the values and hit the button "Send Push Notification" instantly you will receive notification in your Android device(with default icon and sound)

How to customize ACS Push notification?
Here you can use use your custom sounds and icons.


custom icons must be placed in below directory

Here "myicon.png" is custom icon, specified in the push message without the filename extension. For example: in icon text box enter the file name without extension(myicon)

Custom sound must be placed in below directory

Here "beep.wav" is custom sound, specified in the push message with the filename extension. For example: in custom sound text box you have to enter sound filename with extension(beep.wav). Here is the screens of custom notification


Here you can download the complete working project from my Github Appcelerator Titanium Android Push Notification

If anyone found difficulties in push notification implementation feel free to contact me


Sunday, June 3, 2012

Appcelerator Cloud Service Custom Object and Query

Recently Appcelerator integrated cloud services with Titanium, in this post I am going to explain about bacics of Appcelerator Cloud Service(ACS)

What is Mobile Cloud Computing?
Mobile cloud computing is the usage of cloud computing in combination with mobile devices.
Cloud computing exists when tasks and data are kept on the internet(data are stored on servers at a remote location) rather than on individual devices, providing on-demand here to know more

ACS Advantage
  • Create a server backed for your app instantly
  • Launch and scale your app automatically
  • No server coding or administration required
  • Scalability and Reliability
  • Flexibility
  • Reduced Cost
  • Increased Storage

What can we do with ACS?
Appcelerator provides around 15+ cloud services, among that few are

Standard(Tier 1)
  • Users
  • Files
  • Photos
  • Custom objects
  • Emails
  • Push notifications
Advanced(Tier 2)
  • Chats
  • Checkins
  • Events
  • Friends
  • Photo Collection
  • Places
  • Posts
  • Reviews
  • Message
  • Social integration

In this post I am going to explain how to 
  1. How to create cloud app?
  2. How to create cloud  user?
  3. How to create custom object?
  4. How to query custom object?
1. Create cloud App

Open your Titanium Studio and create a new ploject and make sure (Automatically cloud-enable this application should be checked)

After creating the project edit your tiapp.xml file you can see two(development, Production) set of cloud API keys. No need to worry about this it will be automatically mapped.

For example If run the App in simulator or Device it will use Development keys, If you create a signed pakage it will use Production keys.

Then login to Appcelerator cloud console and you can see yor newly created app

2.Create Cloud User

Include the module at top of your file then add below code to create a cloud User, Here I am creating a User with some sample data
   var Cloud = require('');
            username: "testuser1",
            password: "testuser1",
            password_confirmation: "testuser1",
            first_name: "test",
            last_name: "user1"
        }, function (e) {
            if (e.success) {
                var user = e.users[0];
                alert('Created! You are now logged in as ' +;
            else {
             if (e.error && e.message) {
                 alert('Error :' + e.message);   
after creating a cloud user, the user will logged in automatically 
click Manage -> Development -> App Management -> Users
Here you can see the list of users, also you can edit the user detail

3.Create Custom Object

Cloud user can definec their own Custom Objects and object types, add beolow code to create a cloud custom object, before creating a custom object user must be logged in
      login  : 'testuser1',
      password: 'testuser1',
    }, function(e) {
      if (e.success)   {

          classname : 'books',
          fields : {
            book_id : 1,
            title : 'Javascript',
            author : 'Peter'
        }, function(e) {
          if(e.success) {
          } else {
            alert('Error: ' + ((e.error && e.message) || JSON.stringify(e)));
      } else {
        alert('Login Error:' +((e.error && e.message) || JSON.stringify(e)));

click Manage -> Development -> App Management -> Custom Objects
Here you can see the list of custom objects, also you can edit the object

4. Query Custom Object

Here I am using three type of query
  if(e.index == 0){
   var params = {classname: "books",page: 1,per_page: 10}; // which is used for sellect object having classname = "books"
  }else if(e.index == 1){
   var params = {classname: "books",page: 1,per_page: 10, where: { author: "Peter"}};// which is used for sellect object WHERE author = 'Peter' and classname = "books"
  }else if(e.index == 2){
   var params = {classname: "books",page: 1,per_page: 10, where: { "book_id":{"$gte" : 2}}};// which is used for sellect object WHERE book_id > 2 and classname = "books"

    , function(e) {
      if (e.success) {
                opLabel.text = JSON.stringify(e.books);
      } else {
                alert('Error: ' +((e.error && e.message) || JSON.stringify(e)));        

Here you can download the complete working project from my Github account  Appcelerator Titanium Custom Object and Query

Friday, June 1, 2012

Techday7 - Appcelerator Titanium Development workshop in Chennai

Techday7 is organizing a Appcelerator Titanium Development workshop in Chennai on June 16 2012 with the name of Cross Platform Mobile Development using Appcelerator Titanium. Techday7 is providing a 3 hour workshop. This workshop is targeted at the developer to equip them to use Appcelerator’s Titanium platform to create cross platform native mobile applications using HTML, CSS and Javascript skills and open source technologies. Come and learn the recommended practices, techniques and methodology used in Titanium framework. These workshops is designed for individuals who want to become an expert Titanium developer or improve mobile app development skills, we can help you achieve your goals. In this workshop we are going to deliver the speech on following topics

  • Why cross-platform mobile framework? What is Appcelerator Titanium?
  • Getting started with Appcelerator Titnanium
  • Best Practices for Appcelerator Titanium

Cross Platform Mobile Development using Appcelerator Titanium
Cross Platform Mobile Development using Appcelerator Titanium

Techday7 invites you all to attend this event. Kindly RSVP this event to confirm your seats.
Date: 16 June 2012
Time: 9:00 A.M to 1:00 P.M
Venue: IIT Madras Research Park,
Kanagam Road, Taramani,
Chennai – 600 113.
Contact: 044-65180342, 9994526041, 9092049890

Venue Map
Venue Map