Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Contributor
SalmanKhursheed
Posts: 3
Registered: ‎10-06-2010
My Device: Not Specified

Unreadable SMS Problem

Hi,

I am working on an application which is required to send sms to associated contacts to a particular

message.

 

I have read the Knowledge Base Articles and implemented the following technique to send sms.

 


    private boolean sendMessage()
    {
        boolean isSent=false;
        String addr = "sms://+"+number;
        MessageConnection conn = null;
        try
        {
            conn = (MessageConnection) Connector.open(addr);
            //generate a new text message
            TextMessage tmsg = (TextMessage) conn.newMessage(MessageConnection.TEXT_MESSAGE);
            //set the message text and the address
            //tmsg.setAddress(addr);
            tmsg.setPayloadText(message);  
            //finally send our message
            conn.send(tmsg);
            isSent=true;
            
        }
        catch(Exception e)
        {
            System.out.println( e.toString());
        }
        finally
        {
            try
            {
                conn.close();
                conn = null;
                
            }catch(Exception e){}
        }
        return isSent;
    }
    private boolean sendbyDataMessage()
    {
        boolean isSent=false;
            DatagramConnection connection = null;
            try {
                System.out.println("message is -----------------------------------"+message);
                byte[] data = message.getBytes("UTF-8");
                connection = (DatagramConnection) Connector.open( "sms://" + number );
                System.err.println("connection opened-----sending message" + number);
                Datagram dg = connection.newDatagram(connection.getMaximumLength());
                dg.setData(data, 0, data.length);
                
                connection.send(dg);
                isSent=true;
            }
            catch (IOException e)
            {
                //sendMessage();
                System.err.println("Unable to send SMS "+e.toString());
               
            }
            finally {
                try
                {
                    connection.close();
                    connection=null;
                    
                }catch(Exception e){}
            }
            return isSent;
           
    }
    public void run()
    {
           try
            {
                sendbyDataMessage();
            } catch (Exception e) {
                System.out.println(e);
            }
            try
            {
                sendMessage();
            } catch (Exception e) {
                System.out.println(e);
            }
        }

 

 

This is called in a seperate thread but i have got one problem here...

 

SMS sent correctly when the app is open and sms readable at the receiving end.

 

SMS sent correctly when the app is closed but not readable by receiving device.

 

This is tested on the 3 to 5 of US Major Carrier Networks.

What may be the technical problem.

Any help would be appreciated.


Thanks,

Salman Khursheed

salman@appflute.com

 

Please use plain text.