當前位置: 首頁>>代碼示例>>Java>>正文


Java Message.addExtension方法代碼示例

本文整理匯總了Java中org.jivesoftware.smack.packet.Message.addExtension方法的典型用法代碼示例。如果您正苦於以下問題:Java Message.addExtension方法的具體用法?Java Message.addExtension怎麽用?Java Message.addExtension使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.jivesoftware.smack.packet.Message的用法示例。


在下文中一共展示了Message.addExtension方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: sendMessage

import org.jivesoftware.smack.packet.Message; //導入方法依賴的package包/類
public void sendMessage(String body, String chatJid, long timestamp) throws SmackException {
    Random random = new Random(timestamp + body.length() + chatJid.length());
    Log.d(TAG, "Sending message to : " + chatJid);
    MultiUserChat chat = MultiUserChatManager.getInstanceFor(groupChatConnection)
            .getMultiUserChat(chatJid);
    chat.addMessageListener(this);

    Message message = new Message();
    QuickbloxChatExtension extension = new QuickbloxChatExtension();
    extension.setProperty("date_sent", timestamp + "");
    message.setStanzaId(StanzaIdUtil.newStanzaId());
    message.setBody(body);
    message.addExtension(extension);
    message.setType(Message.Type.chat);

    chat.sendMessage(message);
}
 
開發者ID:ukevgen,項目名稱:BizareChat,代碼行數:18,代碼來源:QuickbloxGroupXmppConnection.java

示例2: sendDisplayedReceipt

import org.jivesoftware.smack.packet.Message; //導入方法依賴的package包/類
public void sendDisplayedReceipt(String receiverJid, String stanzaId, String dialog_id) {
    Chat chat;
    if ((chat = privateChats.get(receiverJid)) == null) {
        chat = ChatManager.getInstanceFor(privateChatConnection).createChat(receiverJid, this);
        privateChats.put(receiverJid, chat);
    }

    Message message = new Message(receiverJid);
    Displayed read = new Displayed(stanzaId);
    QuickbloxChatExtension extension = new QuickbloxChatExtension();
    extension.setProperty("dialog_id", dialog_id);

    message.setStanzaId(StanzaIdUtil.newStanzaId());
    message.setType(Message.Type.chat);
    message.addExtension(read);
    message.addExtension(extension);

    try {
        chat.sendMessage(message);
    } catch (SmackException.NotConnectedException ex) {
        Logger.logExceptionToFabric(ex);
        offlineMessages.add(message);
    }
}
 
開發者ID:ukevgen,項目名稱:BizareChat,代碼行數:25,代碼來源:QuickbloxPrivateXmppConnection.java

示例3: sendReceivedReceipt

import org.jivesoftware.smack.packet.Message; //導入方法依賴的package包/類
public void sendReceivedReceipt(String receiverJid, String stanzaId, String dialog_id) {
    Chat chat;
    if ((chat = privateChats.get(receiverJid)) == null) {
        chat = ChatManager.getInstanceFor(privateChatConnection).createChat(receiverJid, this);
        privateChats.put(receiverJid, chat);
    }

    Message message = new Message(receiverJid);
    Received delivered = new Received(stanzaId);
    QuickbloxChatExtension extension = new QuickbloxChatExtension();
    extension.setProperty("dialog_id", dialog_id);

    message.setStanzaId(StanzaIdUtil.newStanzaId());
    message.setType(Message.Type.chat);
    message.addExtension(delivered);
    message.addExtension(extension);

    try {
        chat.sendMessage(message);
    } catch (SmackException.NotConnectedException ex) {
        offlineMessages.add(message);
    }
}
 
開發者ID:ukevgen,項目名稱:BizareChat,代碼行數:24,代碼來源:QuickbloxPrivateXmppConnection.java

示例4: sendPrivateMessage

import org.jivesoftware.smack.packet.Message; //導入方法依賴的package包/類
public void sendPrivateMessage(String body, String receiverJid, long timestamp, String stanzaId) {
    Log.d(TAG, "Sending message to : " + receiverJid);

    Chat chat;
    if ((chat = privateChats.get(receiverJid)) == null) {
        chat = ChatManager.getInstanceFor(privateChatConnection).createChat(receiverJid, this);
        privateChats.put(receiverJid, chat);
    }

    QuickbloxChatExtension extension = new QuickbloxChatExtension();
    extension.setProperty("date_sent", timestamp + "");
    extension.setProperty("save_to_history", "1");

    Message message = new Message(receiverJid);
    message.setStanzaId(stanzaId);
    message.setBody(body);
    message.setType(Message.Type.chat);
    message.addExtension(new Markable());
    message.addExtension(extension);

    try {
        chat.sendMessage(message);
    } catch (SmackException.NotConnectedException ex) {
        offlineMessages.add(message);
    }
}
 
開發者ID:ukevgen,項目名稱:BizareChat,代碼行數:27,代碼來源:QuickbloxPrivateXmppConnection.java

示例5: sendPublicMessage

import org.jivesoftware.smack.packet.Message; //導入方法依賴的package包/類
public void sendPublicMessage(String body, String chatJid, long timestamp, String stanzaId) {
    Log.d(TAG, "Sending message to : " + chatJid);

    MultiUserChat mucChat = publicChats.get(chatJid);

    QuickbloxChatExtension extension = new QuickbloxChatExtension();
    extension.setProperty("date_sent", timestamp + "");
    extension.setProperty("save_to_history", "1");

    Message message = new Message(chatJid);
    message.setStanzaId(stanzaId);
    message.setBody(body);
    message.setType(Message.Type.groupchat);
    message.addExtension(extension);

    try {
        if (mucChat != null) {
            mucChat.sendMessage(message);
        }
    } catch (SmackException.NotConnectedException ex) {
        offlineMessages.add(message);
    }
}
 
開發者ID:ukevgen,項目名稱:BizareChat,代碼行數:24,代碼來源:QuickbloxPrivateXmppConnection.java

示例6: receiptManagerListenerTest

import org.jivesoftware.smack.packet.Message; //導入方法依賴的package包/類
@Test
public void receiptManagerListenerTest() throws Exception {
    DummyConnection c = new DummyConnection();
    c.connect();
    DeliveryReceiptManager drm = DeliveryReceiptManager.getInstanceFor(c);

    TestReceiptReceivedListener rrl = new TestReceiptReceivedListener();
    drm.addReceiptReceivedListener(rrl);

    Message m = new Message("[email protected]", Message.Type.normal);
    m.setFrom("[email protected]");
    m.setStanzaId("reply-id");
    m.addExtension(new DeliveryReceipt("original-test-id"));
    c.processPacket(m);

    rrl.waitUntilInvocationOrTimeout();
}
 
開發者ID:TTalkIM,項目名稱:Smack,代碼行數:18,代碼來源:DeliveryReceiptTest.java

示例7: testSendSimpleXHTMLMessage

import org.jivesoftware.smack.packet.Message; //導入方法依賴的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");
}
   }
 
開發者ID:TTalkIM,項目名稱:Smack,代碼行數:29,代碼來源:XHTMLExtensionTest.java

示例8: shouldReadAllReceivedData1

import org.jivesoftware.smack.packet.Message; //導入方法依賴的package包/類
/**
 * Test the input stream read(byte[], int, int) method.
 * 
 * @throws Exception should not happen
 */
@Test
public void shouldReadAllReceivedData1() throws Exception {
    // create random data
    Random rand = new Random();
    byte[] controlData = new byte[3 * blockSize];
    rand.nextBytes(controlData);

    // get IBB sessions data packet listener
    InBandBytestreamSession session = new InBandBytestreamSession(connection, initBytestream,
                    initiatorJID);
    InputStream inputStream = session.getInputStream();
    StanzaListener listener = Whitebox.getInternalState(inputStream, StanzaListener.class);

    // verify data packet and notify listener
    for (int i = 0; i < controlData.length / blockSize; i++) {
        String base64Data = Base64.encodeToString(controlData, i * blockSize, blockSize);
        DataPacketExtension dpe = new DataPacketExtension(sessionID, i, base64Data);
        Message dataMessage = new Message();
        dataMessage.addExtension(dpe);
        listener.processPacket(dataMessage);
    }

    byte[] bytes = new byte[3 * blockSize];
    int read = 0;
    read = inputStream.read(bytes, 0, blockSize);
    assertEquals(blockSize, read);
    read = inputStream.read(bytes, 10, blockSize);
    assertEquals(blockSize, read);
    read = inputStream.read(bytes, 20, blockSize);
    assertEquals(blockSize, read);

    // verify data
    for (int i = 0; i < bytes.length; i++) {
        assertEquals(controlData[i], bytes[i]);
    }

    protocol.verifyAll();

}
 
開發者ID:TTalkIM,項目名稱:Smack,代碼行數:45,代碼來源:InBandBytestreamSessionMessageTest.java

示例9: shouldSendCloseRequestIfInvalidSequenceReceived

import org.jivesoftware.smack.packet.Message; //導入方法依賴的package包/類
/**
 * If a data stanza(/packet) is received out of order the session should be closed. See XEP-0047 Section
 * 2.2.
 * 
 * @throws Exception should not happen
 */
@Test
public void shouldSendCloseRequestIfInvalidSequenceReceived() throws Exception {
    // confirm close request
    IQ resultIQ = IBBPacketUtils.createResultIQ(initiatorJID, targetJID);
    protocol.addResponse(resultIQ, Verification.requestTypeSET,
                    Verification.correspondingSenderReceiver);

    // get IBB sessions data packet listener
    InBandBytestreamSession session = new InBandBytestreamSession(connection, initBytestream,
                    initiatorJID);
    InputStream inputStream = session.getInputStream();
    StanzaListener listener = Whitebox.getInternalState(inputStream, StanzaListener.class);

    // build invalid packet with out of order sequence
    String base64Data = Base64.encode("Data");
    DataPacketExtension dpe = new DataPacketExtension(sessionID, 123, base64Data);
    Message dataMessage = new Message();
    dataMessage.addExtension(dpe);

    // add data packets
    listener.processPacket(dataMessage);

    // read until exception is thrown
    try {
        inputStream.read();
        fail("exception should be thrown");
    }
    catch (IOException e) {
        assertTrue(e.getMessage().contains("Packets out of sequence"));
    }

    protocol.verifyAll();

}
 
開發者ID:TTalkIM,項目名稱:Smack,代碼行數:41,代碼來源:InBandBytestreamSessionMessageTest.java

示例10: shouldReadAllReceivedData2

import org.jivesoftware.smack.packet.Message; //導入方法依賴的package包/類
/**
 * Test the input stream read() method.
 * 
 * @throws Exception should not happen
 */
@Test
public void shouldReadAllReceivedData2() throws Exception {
    // create random data
    Random rand = new Random();
    byte[] controlData = new byte[3 * blockSize];
    rand.nextBytes(controlData);

    // get IBB sessions data packet listener
    InBandBytestreamSession session = new InBandBytestreamSession(connection, initBytestream,
                    initiatorJID);
    InputStream inputStream = session.getInputStream();
    StanzaListener listener = Whitebox.getInternalState(inputStream, StanzaListener.class);

    // verify data packet and notify listener
    for (int i = 0; i < controlData.length / blockSize; i++) {
        String base64Data = Base64.encodeToString(controlData, i * blockSize, blockSize);
        DataPacketExtension dpe = new DataPacketExtension(sessionID, i, base64Data);
        Message dataMessage = new Message();
        dataMessage.addExtension(dpe);
        listener.processPacket(dataMessage);
    }

    // read data
    byte[] bytes = new byte[3 * blockSize];
    for (int i = 0; i < bytes.length; i++) {
        bytes[i] = (byte) inputStream.read();
    }

    // verify data
    for (int i = 0; i < bytes.length; i++) {
        assertEquals(controlData[i], bytes[i]);
    }

    protocol.verifyAll();

}
 
開發者ID:TTalkIM,項目名稱:Smack,代碼行數:42,代碼來源:InBandBytestreamSessionMessageTest.java

示例11: send

import org.jivesoftware.smack.packet.Message; //導入方法依賴的package包/類
/**
 * Sends a roster to userID. All the entries of the roster will be sent to the
 * target user.
 * 
 * @param roster the roster to send
 * @param targetUserID the user that will receive the roster entries
 * @throws NotConnectedException 
 */
public void send(Roster roster, String targetUserID) throws NotConnectedException {
    // Create a new message to send the roster
    Message msg = new Message(targetUserID);
    // Create a RosterExchange Package and add it to the message
    RosterExchange rosterExchange = new RosterExchange(roster);
    msg.addExtension(rosterExchange);

    XMPPConnection connection = weakRefConnection.get();
    // Send the message that contains the roster
    connection.sendStanza(msg);
}
 
開發者ID:TTalkIM,項目名稱:Smack,代碼行數:20,代碼來源:RosterExchangeManager.java

示例12: addNotificationsRequests

import org.jivesoftware.smack.packet.Message; //導入方法依賴的package包/類
/**
 * Adds event notification requests to a message. For each event type that
 * the user wishes event notifications from the message recepient for, <tt>true</tt>
 * should be passed in to this method.
 * 
 * @param message the message to add the requested notifications.
 * @param offline specifies if the offline event is requested.
 * @param delivered specifies if the delivered event is requested.
 * @param displayed specifies if the displayed event is requested.
 * @param composing specifies if the composing event is requested.
 */
public static void addNotificationsRequests(Message message, boolean offline,
        boolean delivered, boolean displayed, boolean composing)
{
    // Create a MessageEvent Package and add it to the message
    MessageEvent messageEvent = new MessageEvent();
    messageEvent.setOffline(offline);
    messageEvent.setDelivered(delivered);
    messageEvent.setDisplayed(displayed);
    messageEvent.setComposing(composing);
    message.addExtension(messageEvent);
}
 
開發者ID:TTalkIM,項目名稱:Smack,代碼行數:23,代碼來源:MessageEventManager.java

示例13: sendDeliveredNotification

import org.jivesoftware.smack.packet.Message; //導入方法依賴的package包/類
/**
 * Sends the notification that the message was delivered to the sender of the original message
 * 
 * @param to the recipient of the notification.
 * @param packetID the id of the message to send.
 * @throws NotConnectedException 
 */
public void sendDeliveredNotification(String to, String packetID) throws NotConnectedException {
    // Create the message to send
    Message msg = new Message(to);
    // Create a MessageEvent Package and add it to the message
    MessageEvent messageEvent = new MessageEvent();
    messageEvent.setDelivered(true);
    messageEvent.setStanzaId(packetID);
    msg.addExtension(messageEvent);
    // Send the packet
    connection().sendStanza(msg);
}
 
開發者ID:TTalkIM,項目名稱:Smack,代碼行數:19,代碼來源:MessageEventManager.java

示例14: sendComposingNotification

import org.jivesoftware.smack.packet.Message; //導入方法依賴的package包/類
/**
 * Sends the notification that the receiver of the message is composing a reply
 * 
 * @param to the recipient of the notification.
 * @param packetID the id of the message to send.
 * @throws NotConnectedException 
 */
public void sendComposingNotification(String to, String packetID) throws NotConnectedException {
    // Create the message to send
    Message msg = new Message(to);
    // Create a MessageEvent Package and add it to the message
    MessageEvent messageEvent = new MessageEvent();
    messageEvent.setComposing(true);
    messageEvent.setStanzaId(packetID);
    msg.addExtension(messageEvent);
    // Send the packet
    connection().sendStanza(msg);
}
 
開發者ID:TTalkIM,項目名稱:Smack,代碼行數:19,代碼來源:MessageEventManager.java

示例15: sendCancelledNotification

import org.jivesoftware.smack.packet.Message; //導入方法依賴的package包/類
/**
 * Sends the notification that the receiver of the message has cancelled composing a reply.
 * 
 * @param to the recipient of the notification.
 * @param packetID the id of the message to send.
 * @throws NotConnectedException 
 */
public void sendCancelledNotification(String to, String packetID) throws NotConnectedException {
    // Create the message to send
    Message msg = new Message(to);
    // Create a MessageEvent Package and add it to the message
    MessageEvent messageEvent = new MessageEvent();
    messageEvent.setCancelled(true);
    messageEvent.setStanzaId(packetID);
    msg.addExtension(messageEvent);
    // Send the packet
    connection().sendStanza(msg);
}
 
開發者ID:TTalkIM,項目名稱:Smack,代碼行數:19,代碼來源:MessageEventManager.java


注:本文中的org.jivesoftware.smack.packet.Message.addExtension方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。