Ads

Monday, June 11, 2012

Appcelerator Cloud Push Notification in Android

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.

5)Android Push Configuration
It is final step. In Appcelerator Cloud Console go toMy Apps -> Manage ACS -> DEVELOPMENT -> Settings/Android Push Configuration and enter the Application Package in the text box. Your pakage name should be similar to com.xxx.androidpush 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.

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.Icon
custom icons must be placed in below directoryApp_root/platform/android/res/drawable/myicon.png

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)

Sound
Custom sound must be placed in below directoryapp_root/platform/android/assets/sound/beep.wav

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

Thanks for this useful tutorial I have succeeded installing ACS with my android application for the first time but when i have uninstall the app and later i have installed it again i am not able anymore to receive notifications.So what i have to do to be able to receive notification if the user uninstall the app and then install it later.

Hi! This post is very helpful to get my ACS push notification setup and ready.

Here's the problem I faced: it shows "You currently have 1 iOS client, 1 Android client subscribed to push notifications." on my appcelerator account via my.appcelerator.com. However, when I send the push notification, only my that android device never receive it. (My iPhone is able to receive the pushes).

Hi Karthi, I found the source of the problem. I should not have followed the instructions in the https://cloud.appcelerator.com/docs/android#push first before following yours. I changed the AndroidManifest.xml when I should not!

i have implemented the client successfully, thanks ... but im struggling with server side of it. Using js sdk from http://cloud.appcelerator.com/docs/api/v1/push_notifications/notify im getting 401 status code ... unauthorized/should be signed in

Hi Thanks for the reply ... what do you exactly mean by "logging in with cloud user" ... as was logged into https://my.appcelerator.com/apps with the developer account .... and i have also created Users in app managment ...

Hi karthi...Thanks fr such an explantory post on android push using titanium...i have followed all the methods above....evn in the cloud i am gettin one android client registered but the notification not appearing on my device when i try to push it...is dere any access permissions it requires other dan the one alrdy present...

Hi, First, thank you to share your work :)Im newbie on this, and i have question, where you get the module ti.cloudpush ?? i checked on the marketplace on appcelerator but nothing :( Have you a url or maybe its not free ? Thx

Hi, first all, thx for answer me.It woks ! i mean , i have my device token, after im in step 3 and i created my user on my manage ACS, but i have error after compiled.You declare var cloudPush and its work fine but after for step 3 i have message reference Error, "cloud" is not defined. So i changed Cloud.Users by CloudPush.Users but i have a message error, users is not defined.

Hi again :)It works perfectly, thank you for answering fastly :)Last question, so if i wanna integrate this module to an application for android market.The best way is to call function defaultSubscribe directly in CloudPush.retrieveDeviceToken() in success ?It will add my client directly in my manage ACS ?

Thank you for this tutorial. There are a few things that are not entirely clear to me so I hope you will be able to help.

a. In the ACS control panel for the app in question under the Settings tab one of the required entries (Android) is Application Package. What does one enter here - the .apk file name or the application id, i.e com.example.app

b. When one sends out a push progammatically it is easy to send out a notification where you specify the channel. However, it is not clear to me how I do this from the ACS control panel where the options offered are title, alert etc.

For the sake of developing a server PHP program that sends pushnotification to the device, I tried in many ways to use ACS API describedin this link:http://cloud.appcelerator.com/docs/api/v1/push_notifications/notify but Ididn't succeed. By the way I was able to send push notifications manuallythrough the ACS console.

Could you help me with a sample program that proved to realize such aservice ?

Hi, It was good tutorial for push notification implementation.But I have done all the steps told by you(in appcelerator site as well as steps like appId creation and mapping).Whwn i launch the app and click "Register for Puh Notification", I got three alerts, Device Token :'some xyz' ,Subscribed for push Notification and Login success. Even though i got all those, My push console says, "You currently have 0 iOS clients, 0 Android clients subscribed to push notifications". Since no subscription in console, i am unable to receive notification.

Hi, im trying to follow the steps in your tutorial, i already added the module in tiapp.xml, but im failing at step 2, when i try to retrieve the device token im getting this error: "Failed to register for push! com.appcelerator.cloud.push.PushServiceException: Invalid toek request, Message: Unable to generate device token", could you please give me any help with this?, seems like im missing something but i just cant find the problem, thanks!

Thanks for the reply! I tried to completely kill my test app by going to task manager and completely killing the app, but when I do I never get any push messages. If someone completely kills the app, should I still get push messages? Or do I have to setup a background process to make push messaging work if someone completely kills the app?

Hmm, everything seems fine in terms of the messages showing up and the registered device showing up on ACS. However, I get nothing on the android device... is this not supposed to work on the android emulator? Mind you, I don't have an android device to test on.

I tried using the code sample to mine, Did every step and finally I was able to see (1) Android device added on the push notification screen.(same as a screen shot on the blog). Then I tried sending the Notification through the test form provided by appcelerator.

I tried to completely kill my test app by going to task manager and completely killing the app, but when I do I never get any push messages. If someone completely kills the app, should I still get push messages? Or do I have to setup a background process to make push messaging work if someone completely kills the app?

Thats how you defined it - "Push notification allows an app to notify you of new messages or events without the need to actually open the application"

Hi, I am getting same error like "com.appcelerator.cloud.push.PushServiceException: Invalid token request. Message:Proper Android Config can not be found, please provide a valid packagename.". Have you find solution of this?

Hi Karthi,We have a similar problem as other people, All works fine if the app is running but if we kill the app and send a notification we dont have any response till we open the app again.Can you help us.

hi, sorry but i have problems...i should use some library or API??? because the emulator show me the next message: [280,0]ti: module.jsmessage: Uncaught Error: Requested module not found:ti.cloudSource: throw new Error("Requested module not found: " + request);I AM SORRY FOR MY BAD ENGLISH... :(

Hi, I have written a NEW Titanium Android Module for JPUSH - A Chinese Push Service provider - its working and tested and works really well - visit my site for more details - http://kiteplans.info/2014/04/05/module-appcelerator-titanium-alloy-jpush-push-notification-module-android-china-push-non-gcm/

I've put the sound, icon files in the directory as you said but the response from Ti console is "CloudpushModule: (main) [46057,116137] Failed to find icon resource 'appicon.png' in application"and "CloudpushModule: (main) [1,116138] Resources/sound/dingdong.wav"