Display.getInstance().sendSMS("xxxxxxxxxxx", "text"); Not working (J2ME)

4,081 views
Skip to first unread message

anop...@gmail.com

unread,
Jul 31, 2013, 6:13:21 AM7/31/13
to codenameone...@googlegroups.com
I tried sending SMS using the sendSMS() method but it's not working.
I tried it in Nokia C7 with a valid SIM card.

I tried the number in several formats:
1. 00301111111111
2. +301111111111
3. 1111111111

At the end, nothing happened :(

anop...@gmail.com

unread,
Jul 31, 2013, 6:14:44 AM7/31/13
to codenameone...@googlegroups.com, anop...@gmail.com
Sending SMS through the Share Button is not working either

Chen Fishbein

unread,
Jul 31, 2013, 9:45:22 AM7/31/13
to codenameone...@googlegroups.com, anop...@gmail.com
Are you able to send sms using regular J2ME midlet on your device? 


This is the sms j2me code which works fine for me (this is the current implementation) if you can improve this to make it work on your device please let us know:

    public void sendSMS(final String phoneNumber, final String message) throws IOException{
        String address = "sms://" + phoneNumber + ":5000";
        MessageConnection con = null;

        try {
            con = (MessageConnection) Connector.open(address);
            TextMessage txtmessage =
                    (TextMessage) con.newMessage(MessageConnection.TEXT_MESSAGE);
            txtmessage.setAddress(address);
            txtmessage.setPayloadText(message);
            con.send(txtmessage);
        } catch (Exception e) {
            throw new IOException("failed to send sms " + e.getMessage());
        } finally {
            if (con != null) {
                try {
                    con.close();
                } catch (IOException ioe) {
                    ioe.printStackTrace();
                }
            }
        }

    }

anop...@gmail.com

unread,
Aug 1, 2013, 6:11:33 AM8/1/13
to codenameone...@googlegroups.com, anop...@gmail.com
The code you sent me works in one condition: you have to omit the port 5000 from the address (see below)

    public void sendSMS(final String phoneNumber, final String message) throws IOException{

       
String address = "sms://" + phoneNumber; //+ ":5000";

       
MessageConnection con = null;
       
try {
            con
= (MessageConnection) Connector.open(address);

           
System.out.println("Phone="+phoneNumber);

           
TextMessage txtmessage =
                   
(TextMessage) con.newMessage(MessageConnection.TEXT_MESSAGE);
            txtmessage
.setAddress(address);
            txtmessage
.setPayloadText(message);
            con
.send(txtmessage);
       
} catch (Exception e) {
           
throw new IOException("failed to send sms " + e.getMessage());
       
} finally {
           
if (con != null) {
               
try {
                    con
.close();
               
} catch (IOException ioe) {
                    ioe
.printStackTrace();
               
}
           
}
       
}
   
}

Please let me know about the CN1 function

Chen Fishbein

unread,
Aug 2, 2013, 6:47:57 AM8/2/13
to codenameone...@googlegroups.com, anop...@gmail.com
Thanks, I will remove the port# 
Reply all
Reply to author
Forward
0 new messages