WEB开发网
开发学院手机开发Ophone 开发 实现基于OPhone 2.0的GTalk客户端 阅读

实现基于OPhone 2.0的GTalk客户端

 2010-10-19 20:56:29 来源:WEB开发网   
核心提示:package net.blogjava.mobile.gtalk;import org.jivesoftware.smack.PacketCollector;import org.jivesoftware.smack.filter.AndFilter;import org.jivesoftware.smack.fil

package net.blogjava.mobile.gtalk;

import org.jivesoftware.smack.PacketCollector;

import org.jivesoftware.smack.filter.AndFilter;

import org.jivesoftware.smack.filter.FromContainsFilter;

import org.jivesoftware.smack.filter.PacketFilter;

import org.jivesoftware.smack.filter.PacketTypeFilter;

import org.jivesoftware.smack.packet.Message;

import org.jivesoftware.smack.packet.Packet;

import android.os.Handler;

public class MessageReceiver implements Runnable

{

private String mAccount;

private PacketFilter filter;

private OnMessageListener mOnMessageListener;

public PacketCollector mCollector;

public boolean flag = true;

private Handler handler = new Handler()

{

@Override

public void handleMessage(android.os.Message msg)

{

Message message = (Message) msg.obj;

if (mOnMessageListener != null)

{

// 调用processMessage事件方法,以便对聊天消息做进一步地处理

mOnMessageListener.processMessage(message);

}

super.handleMessage(msg);

}

};

public MessageReceiver(String account)

{

mAccount = account;

// 用于过滤只包含帐户信息的聊天消息

new AndFilter(new PacketTypeFilter(Message.class),

new FromContainsFilter(account));

mCollector = GTalk.mConnection.createPacketCollector(filter);

}

@Override

public void run()

{

while (flag)

{

Packet packet = mCollector.nextResult();

if (packet instanceof Message)

{

Message msg = (Message) packet;

android.os.Message message = new android.os.Message();

message.obj = msg;

handler.sendMessage(message);

上一页  1 2 3 4 5 6 7 8  下一页

Tags:实现 基于 OPhone

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接