简体   繁体   English

尝试获取Android jabber应用程序以检查新消息中的字符串并返回一条祝酒消息

[英]Trying to get an Android jabber app to check for a string in new messages and return a toast message

I have been able to create the if statement that checks for the string and it returns the toast message that i created but it keeps showing the toast message every time i open the chat. 我已经能够创建用于检查字符串的if语句,它返回我创建的Toast消息,但是每次我打开聊天时,它始终显示Toast消息。 even if the most recent message doesn't contain the string I am looking for so i am assume it isn't checking to see if it is the last message received and it doesn't check to see if it is unread. 即使最近的消息不包含我要查找的字符串,所以我假设它不会检查是否是最后收到的消息,也不会检查是否未读。 the code is below. 代码如下。 the reason i am trying to do this is because my parents share a facebook account and i want an easy way to display if the message is signed mom or dad. 我尝试执行此操作的原因是因为我的父母共享一个Facebook帐户,并且我想以一种简单的方式来显示邮件是否已由父母签署。 the code below only has the check for mom once it works i will be adding the check for dad signature. 下面的代码仅在工作后才有妈妈的支票,我将添加爸爸签名的支票。 I am using the open source message client Xabber. 我正在使用开源消息客户端Xabber。 Thank you for help. 谢谢你的帮助。

  public void setVisibleChat(String account, String user) {
    final boolean remove = !AccountManager.getInstance()
            .getArchiveMode(account).saveLocally();
    AbstractChat chat = getChat(account, user);
    if (chat == null)
        chat = createChat(account, user);
    else {
        // Mark messages as read and them delete from db if necessary.
        final ArrayList<MessageItem> messageItems = new ArrayList<MessageItem>();
        for (MessageItem messageItem : chat.getMessages()) {
                if (!messageItem.isRead()) {
                messageItem.markAsRead();
                messageItems.add(messageItem);
            }

            if (chat.getLastText().contains("Mom") && (!messageItem.isRead()));{
                Toast.makeText(Application.getInstance(), "Message from Mom!", Toast.LENGTH_SHORT).show();
            }

        }
        Application.getInstance().runInBackground(new Runnable() {
            @Override
            public void run() {
                Collection<Long> ids = getMessageIds(messageItems, remove);
                if (remove)
                    MessageTable.getInstance().removeMessages(ids);
                else
                    MessageTable.getInstance().markAsRead(ids);
            }
        });
    }
    visibleChat = chat;
}

You've got an extra semi-colon here 您这里还有多余的分号

if (chat.getLastText().contains("Mom") && (!messageItem.isRead())); <------

So your next block of code containing the Toast show statement will always be executed. 因此,将始终执行包含Toast show语句的下一个代码块。

Remove the semi-colon 删除分号

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM