收到短信后如何发送回复短信?

发布于 2024-12-12 06:01:35 字数 344 浏览 0 评论 0原文

我有一个应用程序,需要从一个用户向另一个用户发送短信。收到此短信后,它会发回一条回复短信。我开发了一个代码,但问题是它陷入了从一个用户向另一个用户一次又一次发送的循环。对于例如,如果用户 1 向用户 2 发送一些短信,则一条短信会自动发送给用户 1,而用户 1 又会自动再次向用户 2 发送短信,这样反复进行。我怎样才能避免这种情况呢?我只需从用户 2 向用户 1 发送一次回复短信,然后就不会返回短信。请帮我解决此代码。

这是我的代码:

http://pastebin.com/rt2Dd20k

提前致谢。

I have an application which requires sending sms from one user to another.On receiving this sms it sends back a reply sms.I have developed a code but the problem is it goes in aloop of sending again and again from one user to another.For example if user 1 sends some sms to user 2,then a sms is automatically sent to user 1 which in turn automatically sends sms to user 2 again and this goes again and again.How can I avoid that? I have to send the reply sms only once from user 2 to user 1 and then no return sms.Please help me with this code.

Here is my code:

http://pastebin.com/rt2Dd20k

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

荒芜了季节 2024-12-19 06:01:35

如果您知道自动短信回复将包含的确切文本,难道您不能在发送回复的块周围放置一个条件吗?

String autoReplyText = "Whats up";
boolean isAutoReply = msgs[i].getMessageBody().toString().equals(autoReplyText);

if (!isAutoReply) {
    sms.sendTextMessage(str2, null, autoReplyText, pi, null);
}

编辑:如果消息是动态的(根据您的评论,这似乎是必需的),那么您可以确保所有自动回复都以特殊的字符串标记开头,该标记将它们标识为自动回复。这样,如果您收到以您的令牌开头的消息,您就知道不需要回复:

String autoReplyToken = "[BANANA]";
String autoReplyText = autoReplyToken + " dynamic message content";

boolean isAutoReply = msgs[i].getMessageBody().toString().startsWith(autoReplyToken);

if (!isAutoReply) {
    sms.sendTextMessage(str2, null, autoReplyText, pi, null);
}

If you know the exact text that the automated SMS reply will contain, can't you just put a condition around the block that sends the reply?

String autoReplyText = "Whats up";
boolean isAutoReply = msgs[i].getMessageBody().toString().equals(autoReplyText);

if (!isAutoReply) {
    sms.sendTextMessage(str2, null, autoReplyText, pi, null);
}

edit: if the message is dynamic (which it seems that it needs to be, based on your comments) then you could ensure that all automatic replies start with a special string token which identifies them as an automatic reply. This way, if you receive a message that starts with your token, you know you don't need to reply:

String autoReplyToken = "[BANANA]";
String autoReplyText = autoReplyToken + " dynamic message content";

boolean isAutoReply = msgs[i].getMessageBody().toString().startsWith(autoReplyToken);

if (!isAutoReply) {
    sms.sendTextMessage(str2, null, autoReplyText, pi, null);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文