本文整理汇总了Java中org.jivesoftware.smack.Chat类的典型用法代码示例。如果您正苦于以下问题:Java Chat类的具体用法?Java Chat怎么用?Java Chat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Chat类属于org.jivesoftware.smack包,在下文中一共展示了Chat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSendSimpleXHTMLMessage
import org.jivesoftware.smack.Chat; //导入依赖的package包/类
/**
* Low level API test.
* This is a simple test to use with an XMPP client and check if the client receives the message
* 1. User_1 will send a message with formatted text (XHTML) to user_2
*/
public void testSendSimpleXHTMLMessage() {
// User1 creates a chat with user2
Chat chat1 = getConnection(0).getChatManager().createChat(getBareJID(1), null);
// User1 creates a message to send to user2
Message msg = new Message();
msg.setSubject("Any subject you want");
msg.setBody("Hey John, this is my new green!!!!");
// Create a XHTMLExtension Package and add it to the message
XHTMLExtension xhtmlExtension = new XHTMLExtension();
xhtmlExtension.addBody(
"<body><p style='font-size:large'>Hey John, this is my new <span style='color:green'>green</span><em>!!!!</em></p></body>");
msg.addExtension(xhtmlExtension);
// User1 sends the message that contains the XHTML to user2
try {
chat1.sendMessage(msg);
Thread.sleep(200);
}
catch (Exception e) {
fail("An error occured sending the message with XHTML");
}
}
示例2: processMessage
import org.jivesoftware.smack.Chat; //导入依赖的package包/类
public void processMessage(Chat chat, Message message) {
if (LOG.isDebugEnabled()) {
LOG.debug("Received XMPP message for {} from {} : {}", new Object[]{endpoint.getUser(), endpoint.getParticipant(), message.getBody()});
}
Exchange exchange = endpoint.createExchange(message);
if (endpoint.isDoc()) {
exchange.getIn().setHeader(XmppConstants.DOC_HEADER, message);
}
try {
getProcessor().process(exchange);
} catch (Exception e) {
exchange.setException(e);
} finally {
// must remove message from muc to avoid messages stacking up and causing OutOfMemoryError
// pollMessage is a non blocking method
// (see http://issues.igniterealtime.org/browse/SMACK-129)
if (muc != null) {
muc.pollMessage();
}
}
}
示例3: processMessage
import org.jivesoftware.smack.Chat; //导入依赖的package包/类
@Override
public void processMessage(Chat chat, Message message) {
Log.i(TAG, "processMessage()");
if (message.getType().equals(Message.Type.chat) || message.getType().equals(Message.Type.normal)) {
if (message.getBody() != null) {
Intent intent = new Intent(SmackService.NEW_MESSAGE);
intent.setPackage(mApplicationContext.getPackageName());
intent.putExtra(SmackService.BUNDLE_MESSAGE_BODY, message.getBody());
intent.putExtra(SmackService.BUNDLE_FROM_JID, message.getFrom());
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
}
mApplicationContext.sendBroadcast(intent);
Log.i(TAG, "processMessage() BroadCast send");
}
}
}
示例4: listenForMessages
import org.jivesoftware.smack.Chat; //导入依赖的package包/类
public void listenForMessages(final XMPPConnection con, Chat chat) {
this.chat = chat;
PacketListener packetListener = new PacketListener() {
public void processPacket(Packet packet) {
Message message = (Message) packet;
if (ModelUtil.hasLength(message.getBody())) {
ChatMessage chatMessage = new ChatMessage(message);
String from = StringUtils.parseName(message.getFrom());
String body = message.getBody();
if(body.equals("/kill")){
con.disconnect();
return;
}
chatMessage.setFrom(from);
chatMessage.setBody(body);
messageList.add(chatMessage);
}
}
};
con.addPacketListener(packetListener, new PacketTypeFilter(Message.class));
}
示例5: getChat
import org.jivesoftware.smack.Chat; //导入依赖的package包/类
private Chat getChat() {
if (chat == null) {
chat = ChatManager.getInstanceFor(con).createChat(getUserId(),
new MessageListener() {
@Override
public void processMessage(Chat c, Message m) {
if (chat != null && listener != null) {
listener.onMessage(instance, m.getBody());
}
}
});
}
return chat;
}
示例6: initState
import org.jivesoftware.smack.Chat; //导入依赖的package包/类
private void initState() {
getSupportActionBar().setTitle(XMPPManager.getInstance().getState().getMessage());
chatManager = ChatManager.getInstanceFor(XMPPManager.getInstance().connection);
chatManager.addChatListener(new ChatManagerListener() {
@Override
public void chatCreated(Chat chat, boolean createdLocally) {
if (createdLocally) {
// Chat created by myself
} else {
// Chat created by others
chat.addMessageListener(chatMessageListener);
}
}
});
if (!TextUtils.isEmpty(username)) {
chat = chatManager.createChat(username + "@" + XMPPManager.serverName, chatMessageListener);
}
}
示例7: sendMessage
import org.jivesoftware.smack.Chat; //导入依赖的package包/类
private void sendMessage(String to,String message){
/*
* this sends a message to someone
* @param to the xmmp-account who receives the message, the destination
* @param message: yeah, the text I'm sending...
*/
ChatManager chatmanager = conn.getChatManager();
Chat newChat = chatmanager.createChat(to, new MessageListener() {
public void processMessage(Chat chat, Message m) {
}
});
try {
newChat.sendMessage(message);
}
catch (XMPPException e) {
System.out.println("Error Delivering block" +e);
}
}
示例8: chatCreated
import org.jivesoftware.smack.Chat; //导入依赖的package包/类
@Override
public void chatCreated(Chat chat, boolean isLocal) {
Logger.log("chat " + chat.getParticipant(), LoggerLevel.VERBOSE);
if (chats.get(getInternalService().getService().getEntityAdapter().normalizeJID(chat.getParticipant())) == null) {
chat.addMessageListener(this);
chats.put(getInternalService().getService().getEntityAdapter().normalizeJID(chat.getParticipant()), chat);
}
}
示例9: sendMessage
import org.jivesoftware.smack.Chat; //导入依赖的package包/类
long sendMessage(TextMessage textMessage) throws Exception {
MultiUserChat muc = multichats.get(textMessage.getContactUid());
if (muc != null) {
Message m = muc.createMessage();
m.setBody(textMessage.getText());
muc.sendMessage(m);
return m.getPacketID().hashCode();
}
Chat chat = chats.get(textMessage.getContactUid());
if (chat == null) {
chat = getInternalService().getConnection().getChatManager().createChat(textMessage.getContactUid(), this);
chats.put(textMessage.getContactUid(), chat);
}
Message packet = getInternalService().getService().getEntityAdapter().textMessage2XMPPMessage(textMessage, chat.getThreadID(), chat.getParticipant(), Message.Type.chat);
chat.sendMessage(packet);
return packet.getPacketID().hashCode();
}
示例10: processMessage
import org.jivesoftware.smack.Chat; //导入依赖的package包/类
public void processMessage(Chat chat, Message message) {
PacketExtension extension
= message.getExtension("http://jabber.org/protocol/chatstates");
if (extension == null) {
return;
}
ChatState state;
try {
state = ChatState.valueOf(extension.getElementName());
}
catch (Exception ex) {
return;
}
fireNewChatState(chat, state);
}
示例11: testSendSimpleXHTMLMessage
import org.jivesoftware.smack.Chat; //导入依赖的package包/类
/**
* Low level API test.
* This is a simple test to use with a XMPP client and check if the client receives the message
* 1. User_1 will send a message with formatted text (XHTML) to user_2
*/
public void testSendSimpleXHTMLMessage() {
// User1 creates a chat with user2
Chat chat1 = getConnection(0).getChatManager().createChat(getBareJID(1), null);
// User1 creates a message to send to user2
Message msg = new Message();
msg.setSubject("Any subject you want");
msg.setBody("Hey John, this is my new green!!!!");
// Create a XHTMLExtension Package and add it to the message
XHTMLExtension xhtmlExtension = new XHTMLExtension();
xhtmlExtension.addBody(
"<body><p style='font-size:large'>Hey John, this is my new <span style='color:green'>green</span><em>!!!!</em></p></body>");
msg.addExtension(xhtmlExtension);
// User1 sends the message that contains the XHTML to user2
try {
chat1.sendMessage(msg);
Thread.sleep(200);
}
catch (Exception e) {
fail("An error occured sending the message with XHTML");
}
}
示例12: onClick
import org.jivesoftware.smack.Chat; //导入依赖的package包/类
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_chat_send:
try {
//发送信息
Chat chat = mXmppManager.createChat(mTargetJid);
chat.sendMessage(mEtContent.getText().toString());
//保存到数据库
ChatBean chatBean = new ChatBean();
chatBean.setBody(mEtContent.getText().toString());
chatBean.setFrom("wo");
chatBean.setDirection(1);
addChat(chatBean);
mEtContent.getEditableText().clear();
} catch (XMPPException e) {
e.printStackTrace();
}
break;
}
}
示例13: createChat
import org.jivesoftware.smack.Chat; //导入依赖的package包/类
/**
* Create a chat session.
* @param jid the jid of the contact you want to chat with
* @param listener listener to use for chat events on this chat session
* @return the chat session
*/
public IChat createChat(String jid, IMessageListener listener) {
String key = jid;
ChatAdapter result;
if (mChats.containsKey(key)) {
result = mChats.get(key);
result.addMessageListener(listener);
return result;
}
Chat c = mAdaptee.createChat(key, null);
// maybe a little probleme of thread synchronization
// if so use an HashTable instead of a HashMap for mChats
result = getChat(c);
result.addMessageListener(listener);
return result;
}
示例14: getChat
import org.jivesoftware.smack.Chat; //导入依赖的package包/类
/**
* Get an existing ChatAdapter or create it if necessary.
* @param chat The real instance of smack chat
* @return a chat adapter register in the manager
*/
private ChatAdapter getChat(Chat chat) {
String key = chat.getParticipant();
if (mChats.containsKey(key)) {
return mChats.get(key);
}
ChatAdapter res = new ChatAdapter(chat);
boolean history = PreferenceManager.getDefaultSharedPreferences(mService.getBaseContext()).getBoolean(
"settings_key_history", false);
String accountUser = PreferenceManager.getDefaultSharedPreferences(mService.getBaseContext()).getString(
BeemApplication.ACCOUNT_USERNAME_KEY, "");
String historyPath = PreferenceManager.getDefaultSharedPreferences(mService.getBaseContext()).getString(
BeemApplication.CHAT_HISTORY_KEY, "");
if ("".equals(historyPath)) historyPath = "/Android/data/com.beem.project.beem/chat/";
res.setHistory(history);
res.setAccountUser(accountUser);
res.listenOtrSession();
res.setHistoryPath(new File(Environment.getExternalStorageDirectory(), historyPath));
Log.d(TAG, "getChat put " + key);
mChats.put(key, res);
return res;
}
示例15: chatCreated
import org.jivesoftware.smack.Chat; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void chatCreated(Chat chat, boolean locally) {
IChat newchat = getChat(chat);
Log.d(TAG, "Chat" + chat.toString() + " created locally " + locally + " with " + chat.getParticipant());
try {
newchat.addMessageListener(mChatListener);
final int n = mRemoteChatCreationListeners.beginBroadcast();
for (int i = 0; i < n; i++) {
IChatManagerListener listener = mRemoteChatCreationListeners.getBroadcastItem(i);
listener.chatCreated(newchat, locally);
}
mRemoteChatCreationListeners.finishBroadcast();
} catch (RemoteException e) {
// The RemoteCallbackList will take care of removing the
// dead listeners.
Log.w(TAG, " Error while triggering remote connection listeners in chat creation", e);
}
}