`
longgangbai
  • 浏览: 7315879 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

androidpn的学习研究(三)androidpn-server服务端几个类说明

 
阅读更多

        AndroidPN(Android Push Notification) 是一个基于XMPP协议的Java开源推送通知实现,它包含了完整的客户端和服务端。

AndroidPN基于Openfire下的一些开源项目构建。

 AndroidPN服务器包含两个部分,

      一个是侦听在5222端口上的XMPP服务,负责与客户端的XMPPConnection类进行通信,作用是用户注册和身份认证,并发送推送通知消息。

      另外一部分是Web服务器,采用一个轻量级的HTTP服务器,负责接收用户的Web请求。

最上层包含四个组成部分,分别是SessionManager,Auth Manager,PresenceManager以及Notification Manager。

        SessionManager负责管理客户端与服务器之间的会话。

        Auth Manager负责客户端用户认证管理。

        Presence Manager负责管理客户端用户的登录状态。

        NotificationManager负责实现服务器向客户端推送消息功能。

 

IQHandler消息处理器的类:

     IQHandler:消息处理器抽象类。

     IQAuthHandler:权限协议的消息处理类,消息的类型为:jabber:iq:auth

     IQRegisterHandler:用户注册的消息处理类,消息类型为: jabber:iq:register

     IQRosterHandler:用户消息交互类,消息类型为:jabber:iq:roster

     PresenceUpdateHandler:用户状态展现变化处理类。内部调用,不具有类型。

 NotificationManager源代码:

public class NotificationManager {

    private static final String NOTIFICATION_NAMESPACE = "androidpn:iq:notification";

    private final Log log = LogFactory.getLog(getClass());

    private SessionManager sessionManager;

    /**
     * Constructor.
     */
    public NotificationManager() {
        sessionManager = SessionManager.getInstance();
    }

    /**
     * Broadcasts a newly created notification message to all connected users.
     * 
     * @param apiKey the API key
     * @param title the title
     * @param message the message details
     * @param uri the uri
     */
    public void sendBroadcast(String apiKey, String title, String message,
            String uri) {
        log.debug("sendBroadcast()...");
        IQ notificationIQ = createNotificationIQ(apiKey, title, message, uri);
        for (ClientSession session : sessionManager.getSessions()) {
            if (session.getPresence().isAvailable()) {
                notificationIQ.setTo(session.getAddress());
                session.deliver(notificationIQ);
            }
        }
    }

    /**
     * Sends a newly created notification message to the specific user.
     * 
     * @param apiKey the API key
     * @param title the title
     * @param message the message details
     * @param uri the uri
     */
    public void sendNotifcationToUser(String apiKey, String username,
            String title, String message, String uri) {
        log.debug("sendNotifcationToUser()...");
        IQ notificationIQ = createNotificationIQ(apiKey, title, message, uri);
        ClientSession session = sessionManager.getSession(username);
        if (session != null) {
            if (session.getPresence().isAvailable()) {
                notificationIQ.setTo(session.getAddress());
                session.deliver(notificationIQ);
            }
        }
    }

    /**
     * Creates a new notification IQ and returns it.
     */
    private IQ createNotificationIQ(String apiKey, String title,
            String message, String uri) {
        Random random = new Random();
        String id = Integer.toHexString(random.nextInt());
        // String id = String.valueOf(System.currentTimeMillis());

        Element notification = DocumentHelper.createElement(QName.get(
                "notification", NOTIFICATION_NAMESPACE));
        notification.addElement("id").setText(id);
        notification.addElement("apiKey").setText(apiKey);
        notification.addElement("title").setText(title);
        notification.addElement("message").setText(message);
        notification.addElement("uri").setText(uri);

        IQ iq = new IQ();
        iq.setType(IQ.Type.set);
        iq.setChildElement(notification);

        return iq;
    }
}

 

其中:

    发布订阅式的发送消息调用方法:

    /**
     * Broadcasts a newly created notification message to all connected users.
     *
     * @param apiKey the API key
     * @param title the title
     * @param message the message details
     * @param uri the uri
     */
    public void sendBroadcast(String apiKey, String title, String message,
            String uri);

 

 

 

点对点的发送消息调用方法:

    /**
     * Sends a newly created notification message to the specific user.
     *
     * @param apiKey the API key
     * @param title the title
     * @param message the message details
     * @param uri the uri
     */
    public void sendNotifcationToUser(String apiKey, String username,
            String title, String message, String uri);

 

创建发送消息的方法:

    /**
     * Creates a new notification IQ and returns it.
     */
    private IQ createNotificationIQ(String apiKey, String title,
            String message, String uri);

分享到:
评论
1 楼 wenjiefeng 2012-10-13  
你好,在andrioidpn-client客户端源码里,NotificationDetailsActivity这个类里,下面的参数都是什么意思呢
Intent intent = getIntent();
String notificationId = intent
.getStringExtra(Constants.NOTIFICATION_ID);
String notificationApiKey = intent
.getStringExtra(Constants.NOTIFICATION_API_KEY);
String notificationTitle = intent
.getStringExtra(Constants.NOTIFICATION_TITLE);
String notificationMessage = intent
.getStringExtra(Constants.NOTIFICATION_MESSAGE);
String notificationUri = intent
.getStringExtra(Constants.NOTIFICATION_URI);

疑惑1、 这几个参数代表什么意思呢, notificationId; notificationApiKey; notificationTitle; notificationMessage; notificationUri;
我看源码里好几处都用到这几个参数 ,

疑惑2、 现在服务端已经能将消息推送到服务端了并增加了一些参数,推送的消息里增加了距离distance等参数,该在客户端的哪个类里获取这些值呢

相关推荐

    androidpn-client-0.5.0和androidpn-server-0.5.0-bin

    客户端主要包含以下几个关键部分: 1. **注册过程**:当用户安装应用后,客户端会通过与服务器进行交互,获取一个唯一的设备ID,并注册到服务器的推送列表中。 2. **后台监听**:客户端在后台持续运行,通过保持一...

    androidpn-bin-server-0.5.0

    这一过程涉及到以下几个关键技术点: 1. **TCP/IP通信**:AndroidPN服务端通常通过TCP/IP协议与客户端建立持久连接,确保通知能够及时、可靠地送达。这种连接方式允许服务器在任何时间向设备发送数据,而无需等待...

    androidpn-tomcat-server端

    AndroidPN服务器端主要包含以下几个关键组件和技术: 1. **TCP连接**:服务器需要与客户端(即Android设备)建立持久的TCP连接,以便在需要时迅速发送推送消息。 2. **协议设计**:服务器和客户端之间的通信需要一...

    androidpn客户端与服务端

    `androidpn-server-0.5.0`包含了服务端的源代码。服务端通常由以下几部分组成: 1. **注册接口**:当一个新的Android设备需要接收推送通知时,它会通过API向服务端注册,提供一个唯一标识(如IMEI)和接收通知的...

    androidpn消息推送-tomcat版

    客户端主要包括以下几个部分: 1. **控制器(XmppManager)**:负责管理连接信息(如XMPP端口、IP地址、用户名和密码),并维护连接状态。 2. **消息解析处理**: - `NotificationIQ`:用于解析特定格式的消息。 - ...

    androidPN server端源码eclipse tomcat版

    AndroidPN的核心部分是它的`PushServer`类,这个类负责接收客户端的注册请求,并通过Google Cloud Messaging (GCM) 或者 Firebase Cloud Messaging (FCM) 与Android设备进行通信。 在实际使用中,你需要配置服务器...

    androidpn 消息推送客户端+服务器端

    客户端的实现包括以下几个关键点: 1. **注册过程**:首次启动时,客户端会获取设备的IMEI(国际移动设备身份码)或Google提供的GCM(Google Cloud Messaging)注册ID,并将这些信息发送到服务器进行注册。 2. **...

    androidpn消息推送完善版,基于web服务器

    客户端的设计主要关注以下几个关键组件: **1. 控制器** XmppManager作为客户端的主要控制器,负责管理连接信息,包括XMPP端口号、服务器IP地址、用户名和密码等,并维护这些连接的状态。 **2. 消息解析处理** ...

    Android推送框架 androidpn.doc

    - Server部分主要包括几个关键包: 1) `org.androidpn.server.dao`、`org.androidpn.server.model`和`org.androidpn.server.service`使用Hibernate与数据库交互,实现用户登录认证。实际开发中,这部分可以根据...

    android电子商城

    首先,从【描述】中我们可以看出,这个项目包括了以下几个关键部分: 1. **红孩子电子商城服务端源码**:这部分是整个电子商城系统的核心,负责处理用户请求、管理商品数据、处理订单、支付等业务逻辑。开发者可以...

Global site tag (gtag.js) - Google Analytics