使用J2ME接收短信

编程入门 行业动态 更新时间:2024-10-27 06:31:55
本文介绍了使用J2ME接收短信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试制作一个J2ME应用程序以发送和接收文本消息.我已经完成了发送部分的操作,但是我无法收到任何消息.

I am trying to make a J2ME application to SEND and RECEIVE text messages. I'm done with the sending part of it but I am not able to receive any message..

下面是我为了接收短信而尝试的内容;

Below is what I tried in order to receive text message;

try { MessageConnection conn = (MessageConnection) Connector.open("sms://:50001"); conn.setMessageListener(new MessageListener() { public void notifyIncomingMessage(MessageConnection conn) { try { Message msg; msg = conn.receive(); if (msg instanceof TextMessage) { TextMessage tmsg = (TextMessage) msg; stringItem.setText("Msg: " + tmsg.getPayloadText()); System.out.println(tmsg.getPayloadText()); } // else if(msg instanceof BinaryMessage) { // ..... // } else { // ...... // } } catch (IOException ex) { ex.printStackTrace(); } finally { try { conn.close(); } catch (IOException ex) { ex.printStackTrace(); } } } }); } catch (Exception e1) { System.out.println(e1); }

但是这不起作用...也没有错误显示...我在做什么错?...我们可以使用J2ME接收消息吗?

But this is not working...No errors are showing up either...what is that I am doing wrong?...Can we receive message using J2ME?

发送消息的代码:(已更新)

MessageConnection conn = (MessageConnection) Connector.open("sms://:50001"); TextMessage tmsg = (TextMessage) conn.newMessage(MessageConnection.TEXT_MESSAGE); tmsg.setPayloadText(message); tmsg.setAddress("sms://" + number); conn.send();

我同时具有两种不同形式的send和receive函数.我所做的就是在两个不同的手机中安装并启动该应用程序,将消息从一个手机发送到另一个手机,然后在另一个手机中接收.

I have both the send and receive functions in two different forms. What I did is to install and start the application in two different mobiles, send a message from one mobile to the other and receive in the other.

消息已成功发送和接收,但未在应用程序中发送和接收.该消息将转到另一部手机的收件箱.

The message is sent and received successfully, but not in the application. The message goes to the inbox of the other mobile.

我该怎么办?

推荐答案

尝试使用5000端口号.

try 5000 port no.

某些手机将此端口用作短信监听器

some phone have this port as sms listener

更多推荐

使用J2ME接收短信

本文发布于:2023-11-27 22:52:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639940.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:短信   J2ME

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!