`
rensanning
  • 浏览: 3548625 次
  • 性别: Icon_minigender_1
  • 来自: 大连
博客专栏
Efef1dba-f7dd-3931-8a61-8e1c76c3e39f
使用Titanium Mo...
浏览量:38145
Bbab2146-6e1d-3c50-acd6-c8bae29e307d
Cordova 3.x入门...
浏览量:607306
C08766e7-8a33-3f9b-9155-654af05c3484
常用Java开源Libra...
浏览量:682331
77063fb3-0ee7-3bfa-9c72-2a0234ebf83e
搭建 CentOS 6 服...
浏览量:89355
E40e5e76-1f3b-398e-b6a6-dc9cfbb38156
Spring Boot 入...
浏览量:401851
Abe39461-b089-344f-99fa-cdfbddea0e18
基于Spring Secu...
浏览量:69694
66a41a70-fdf0-3dc9-aa31-19b7e8b24672
MQTT入门
浏览量:91719
社区版块
存档分类
最新评论

【转】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.
  • Cloudpush Module Implementation
  • Retrieve Device Token
  • Cloud User Login
  • Subscribe  a Channel
  • 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

CloudPush.retrieveDeviceToken({
        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



Cloud.Users.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

Cloud.PushNotifications.subscribe({
    channel: 'alert', // "alert" is channel name
    device_token: deviceToken,
    type: 'android'
}, function (e){
    if (e.success) {
       alert('Subscribed for Push Notification!');
    }else{
        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 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.

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.

Icon
custom icons must be placed in below directory
App_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 icons must be placed in below directory
App_root/Resources/sound/beep.wav

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




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

原文:这里
  • 大小: 41 KB
  • 大小: 16 KB
  • 大小: 9.4 KB
  • 大小: 27.3 KB
  • 大小: 42.2 KB
  • 大小: 57.5 KB
分享到:
评论
2 楼 rensanning 2012-08-01  
wang_godsun 写道
请问这个云push 是免费的吗?速度如何?

PUSH 以前是有限制的,每月125万次调用上线,现在已经无限制免费了!

他们云服务器在美国,速度上肯定会是有影响的。你可以自己试试。
1 楼 wang_godsun 2012-08-01  
请问这个云push 是免费的吗?速度如何?

相关推荐

Global site tag (gtag.js) - Google Analytics