A Titanium module for registering a device with GCM and handling notifications sent to the device.
Android platform are using c2dm for push notification, but because c2dm have stopped accept new user, so we have decide to use the new service that google provided which is Google Cloud Messaging (GCM).
Current Latest version is 0.5
Topics Covered
Change Log
How to use this module in a Titanium project (for people that use my pre-built module)
Sending Notifications (from a server)
Steps to build module for Titanium (Mac Users) (for people that who want to create their own gcm module)
Documents
Change Log
v0.6
Fixed most of the issue.
Compatible with Titanium SDK 3.2.0 and higher including 3.2.3
v0.5
Fixed push notification id which does not replace the notification in you list.
Integrated vibration and sound property when sending message from server.
Example php message:
Changed from getSystemProperties() to getAppProperties() at C2dmModule.java and GCMIntentService.java
fixed clicking on the notification does what is expected
Changed behaviour so that if message is null we don't display a notification
able to push notification by vibration
v0.2
stop to use SENDER_ID
remove senderID from the parameters of "registerC2dm"
auto generate permission in timodule.xml
store the wall push data into "com.activate.gcm.last_data" (stringified json)
call the callback (will not work if app isn't running and V8)
How to use this module in a Titanium project
Copy the .zip into your titanium project at root level. You may use my zip module as well, inside /dist/com.activate.gcm-android-0.1.zip. Double click on the zip file, the zip should be unzip inside the folder name "module".
Insert some properties into tiapp.xml. I have upload my project tiapp.xml to this project, please navigate to /example/tiapp.xml for the references.
After that, you also can refer to the /example/PushNotification.js as reference how to use push notification android in titanium. I have provided example into it.
tiapp.xml properties
Add these to your tiapp.xml file inside the ti:app group.
"The Intent object associated with the notification determines what happens when the user clicks on the notification. In this case, we simply launch the application. The intent in this sample uses a className to identify the activity to launch."
"A Titanium application's main activity generally has the class name:"
<app_id>.<Appname>Activity
"For example, in this case the test application has the app ID com.appcelerator.notificationsample and app name NotificationSample, so the activity class name is:"
For example: --id=com.activate.gcm, --android=/Applicatoins/android-sdk
Once the module project create success, copy the gcm/gcm-client/src folder from you have downloaded at Android SDK Manager into the module src folder.
Please make changes of the sdk path at the build.properties, such as titanium.platoform, android.platform, google.apis, and android.ndk
Now what you want to do is create the interface class between Java native code with titanium javascript using the Kroll Method. For more information please read here:
You also can take my source code as reference on how to create the interface. The source code is provided in this project which inside /src folder.
After complete setup all the class and interface, using ANT 1.8 to compile the module. To compile the module, we have to compile on build.xml. Now, navigate the ANT using terminal and type the command as follow.
请发表评论