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 Developer
Posts: 33
Registered: ‎07-16-2008
My Device: bold

Recive sms using port

My application can recive sms notification  but all msgs appering inbox also i mentioned port no but it is not works ?any suggestion?

 

_dc = (DatagramConnection)Connector.open("sms://5000");

 


 

 

 

BlackBerry Development Advisor
Posts: 15,125
Registered: ‎07-09-2008
My Device: BlackBerry Passport
My Carrier: Bell

Re: Recive sms using port

This is by design.  Please see the note at the bottom of this article for information on how to prevent an SMS message from appearing in the inbox.

 

How To - Use SMS to notify an application 
Article Number: DB-00533

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800563/How_To_...

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
New Developer
Posts: 33
Registered: ‎07-16-2008
My Device: bold

Recive sms using port

Thank u mark, here i got a error message while sending sms via gsm modem through AT commands,

 

  I can send sms in pdu and udh mode via my Gsm modem whenever i changed the Protocol Identifier TP-PID to 64 and the Digital Coding Scheme TP-DCS to  244 i got an Error message in Microsft HT  (in PDU and UDH mode my msg having TP-PID- (00)  TP-DCS -(00) Octet(s) itsworking fine if i change PID to 40,DCS to F4 i got an ERROR) wats my problem can u help me on this?..,

 

Regards,

 jeyaprakash.c.

 

 

 

New Developer
Posts: 4
Registered: ‎12-28-2009
My Device: 8300

Re: Recive sms using port

i write code for registery to get message receiving notification. but code not working. no notification come when message received. please help me. I also activate run on startup option on this code.

my code:

 


    //package subin.rnd.mobile.game;
    
    import javax.microedition.io.Connector;
    import javax.wireless.messaging.MessageConnection;
    import javax.wireless.messaging.MessageListener;
import javax.wireless.messaging.TextMessage;

import net.rim.device.api.ui.component.Dialog;
    
    public class SmsListener
implements MessageListener
    {
        private int port;
    private MessageConnection messageConnection;
    
    public SmsListener(int port)
        {
            try
            {
                port=6222;
                this.messageConnection = (MessageConnection) Connector.open("sms://");
                this.messageConnection.setMessageListener(this);
            }
            catch (Exception e)
            {
                Dialog.alert("Exception: " + e);
               // System.out.println("Exception: " + e);
            }
        }
    
        public void notifyIncomingMessage(MessageConnection messageConnection)
        {
            //System.out.println("Recieved SMS from " + messageConnection);
            Dialog.alert("Recieved SMS: " +  messageConnection);  
            new Thread()
            {
                MessageConnection conn;
                Thread set(MessageConnection conn)
                {
                    this.conn = conn;
                    return (this);
                }
                public void run()
                {
                    try
                    {
                        TextMessage msg = (TextMessage) conn.receive();
                        Dialog.alert("Recieved SMS: " + msg.getPayloadText());  
                        //System.out.println("Recieved SMS: " + msg.getPayloadText());
                    }
                    catch (Exception e)
                    {
                        Dialog.alert("SMS recieve Exception " + e);
                       //System.out.println("SMS recieve Exception " + e);
                    }
                }
            }.set(messageConnection).start();
        }
    }

New Developer
Posts: 4
Registered: ‎12-28-2009
My Device: 8300

Re: Recive sms using port

I also try this code, but no result.

 

 

import java.io.IOException;
import javax.microedition.midlet.*;
import javax.microedition.io.*;
import javax.wireless.messaging.*;

import net.rim.device.api.ui.component.Dialog;

public class Example extends MIDlet implements MessageListener {
    MessageConnection messconn;
    boolean done;
    Reader reader;

    // Initial tests setup and execution.
    public void startApp() {
        try {
            // Start a message-reading thread.
            done = false;
            reader = new Reader();
            new Thread(reader).start();
            // Get our receiving port connection.
            messconn = (MessageConnection) Connector.open("sms://:6222");
            // Register a listener for inbound messages.
            messconn.setMessageListener(this);
        } catch (IOException e) {
            // Handle startup errors
        }
    }

    // Asynchronous callback for inbound message.
    public void notifyIncomingMessage(MessageConnection conn) {
        if (conn == messconn) {
            reader.handleMessage();
        }
    }

    // Required MIDlet method - release the connection and signal the reader thread to terminate.
    public void pauseApp() {
        done = true;
        try {
            messconn.close();
        } catch (IOException e) {
            // Handle errors
        }
    }

    // Required MIDlet method - shutdown.
    // @param unconditional forced shutdown flag
    public void destroyApp(boolean unconditional) {
        done = true;
        try {
            messconn.setMessageListener(null);
            messconn.close();
        } catch (IOException e) {
            // Handle shutdown errors.
        }
    }

    // Isolate blocking I/O on a separate thread, so callback can return immediately.
    private class Reader implements Runnable {
        private int pendingMessages = 0;

        // The run method performs the actual message reading.
        public void run() {
            while (!done) {
                synchronized (this) {
                    if (pendingMessages == 0) {
                        try {
                            wait();
                        } catch (Exception e) {
                            // Handle interruption
                        }
                    }
                    pendingMessages--;
                }
                // The benefit of the MessageListener is here. This thread could via similar
                // triggers be handling other kind of events as well in addition to just receiving
                // the messages.
                try {
                    Message mess = messconn.receive();
                    Dialog.alert("Received");
                } catch (IOException ioe) {
                    // Handle reading errors
                }
            }
        }

        // Invoked from notifyIncomingMessage() to handle the incoming message.
        public synchronized void handleMessage() {
            pendingMessages++;
            notify();
        }
    }

}

New Developer
Posts: 13
Registered: ‎12-26-2009
My Device: 8120
My Carrier: tmobile

Re: Recive sms using port

How do you format a system message like this when the message originates from another BB device and not a server?

Contributor
Posts: 12
Registered: ‎09-16-2010
My Device: 9000
My Carrier: t-mobile

Re: Recive sms using port

even I have this question guys.. Please let us know..

 

Basically we must be able to stop messages going into sms inbox when its received from another BB device sendign a normal sms on the default port..

New Developer
Posts: 44
Registered: ‎09-07-2009
My Device: Not Specified

Re: Recive sms using port

can we delete sms from inbox? after app read sms?

Developer
Posts: 38
Registered: ‎10-27-2010
My Device: Blackberry Torch 9800

Re: Recive sms using port

Hi ddrabo,

When sending an sms from another BB device.. u can use the SMSPacketHeader.

chk the following example for formatting a sms in BB device before sending

SmsAddress iSmsAddress = new SmsAddress("//123215461231");

// retrieve the SMS Packet Header to set the following....
// to set Message Class as CLASS_0
SMSPacketHeader iSPH_Header = iSmsAddress.getHeader();
iSPH_Header.setMessageClass(SMSPacketHeader.MESSAGE_CLASS_0);

//creating new Datagram
Datagram iDG_Message = iDGC.newDatagram(iDGC.getMaximumLength());

((DatagramBase)iDG_Message).setAddressBase(iSmsAddress);
iDG_Message.setData(MessageData,0,MessageData.length);

iDGC.send(iDG_Message);

 

 

check out the SMSPacketHeader and SMSAddress in the API reference document