hey, i m developing a mobile application in which i need to send and recieve a message,any1 who can help me with its code .thanx in advance
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
hey, i m developing a mobile application in which i need to send and recieve a message,any1 who can help me with its code .thanx in advance
Hello neha,
Welcome to the Java Programming Forums.
I know of two solutions you can try.
WMA (Wireless Messaging API) is a wireless messaging api defined in MIDP 2.0. These apis are designed to handle text, binary and multipart messages. To make a connection, the application obtains an object implementing the MessageConnection from the Connector class by providing an URL connection string that identifies the address./* Make a connection */ public boolean connectSMSServer() { try { messageConnection messageConnection = (MessageConnection)Connector.open("sms://:" + port); messageConnection.setMessageListener(this); } catch (Exception e) { } } /* Send text message */ public void sendTextmessage(String address,String message) { try { //creates a new TextMessage TextMessage textMessage = (TextMessage)messageConnection.newMessage( MessageConnection.TEXT_MESSAGE, address); textMessage.setPayloadText(message); messageConnection.send(textMessage); } catch (Exception e) { } } /* Recieve text message */ public void receiveTextMessage() { try { Message message = messageConnection.receive(); if (message instanceof TextMessage) { TextMessage textMessage = (TextMessage)message; } else { //Message can be binary or multipart } } catch (Exception e) { } } /* Notify Incoming Message */ public synchronized void notifyIncomingMessage(MessageConnection conn) { //notiy thread of incoming message synchronized (this) { notify(); } } /* Close Connection */ public void closeConnection() { if (messageConnection != null) { try { messageConnection.setMessageListener(null); messageConnection.close(); } catch (Exception e) { } } } }
WMAPI allows Java ME applications to access messaging functionalities, as sending and receiving SMS and MMS messages. This article explains how to use it to send a simple text message.public boolean sendSms(String number, String message){ boolean result = true; try { //sets address to send message String addr = "sms://"+number; // opens connection MessageConnection conn = (MessageConnection) Connector.open(addr); // prepares text message TextMessage msg = (TextMessage)conn.newMessage(MessageConnection.TEXT_MESSAGE); //set text msg.setPayloadText(message); // send message conn.send(msg); conn.close(); } catch (SecurityException se) { // probably the user has not allowed to send sms // you may want to handle this differently result = false; } catch (Exception e) { result = false; } return result; }
How to Send Text SMS in Java ME - Forum Nokia Wiki
I have limited experience with this so hopefully someone else here can help you move forward.
Please use [highlight=Java] code [/highlight] tags when posting your code.
Forum Tip: Add to peoples reputation by clicking the button on their useful posts.
i have already tried similar code..its not working..actualy i m making a project on security in mobile banking using steganography ..if ne 1 can help me with lil bit of its code..it ll b nice
thanxx...