How to detect an incomming SMS? -HELPPPP

Hello everyone,

This is my first post in this forum. So far, it has helped me a lot. But since a few days, I have had a problem. I want to detect an incomming SMS. I read some post and I found a few pieces of codes that are interesting. But, I failed to do so.

Here are a few links I've read:

-http://www.j2mepolish.org/javadoc/j2me/de/enough/polish/messaging/MessageListener.html

-http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800563/What _...

- http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800563/How_To _...

- http://supportforums.blackberry.com/t5/Java-Development/notifyIncomingMessage-only-called-for-first-...

- http://supportforums.blackberry.com/t5/Java-Development/How-to-listen-to-incoming-sms-message-only/m...

I will stop here with links.

Now, here is my code:

/*
 * hw.java
 *
 * © , 2003-2008
 * Confidential and proprietary.
 */

import java.util.*;
import java.lang.*;
import java.io.*;
import java.io.IOException;
import javax.microedition.location.*;
import javax.microedition.io.*;
import javax.microedition.io.file.*;
import javax.microedition.pim.*;
import javax.wireless.messaging.*;
import net.rim.device.api.io.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;
import net.rim.device.api.i18n.*;
import net.rim.blackberry.api.invoke.*;

/**
 *
 */
class hw extends UiApplication {
    public static void main(String[] args)
    {
        hw instance = new hw();
        instance.enterEventDispatcher();
    }
    public hw()
    {
        pushScreen(new SalutationScreen());
    }
}

class SalutationScreen extends MainScreen implements Runnable //, MessageListener
{
    private Thread t;
    private MessageConnection _mc;

    public SalutationScreen()
    {
        super();
        LabelField applicationTitle =
            new LabelField("Hello World Title");
        setTitle(applicationTitle);
        RichTextField helloWorldTextField = new RichTextField("Hello World!");
        add(helloWorldTextField);

        t = new Thread(this);
        t.start();
/*
        try {
            _mc = (MessageConnection)Connector.open("sms://:0");
            _mc.setMessageListener(this);
            helloWorldTextField = new RichTextField("setMessageListener : done");
            add(helloWorldTextField);
        }
        catch (IOException e) {
            helloWorldTextField = new RichTextField("erreur constructeur : " + e);
            add(helloWorldTextField);
        }
*/
    }

    public boolean onClose()
    {
        Dialog.alert("Bye World!");
        System.exit(0);
                return true;
    }

    public void run()
    {
        try{
            DatagramConnection _dc = (DatagramConnection)Connector.open("sms://:0");

            for(;;)
            {
                Datagram d = _dc.newDatagram(_dc.getMaximumLength());
                _dc.receive(d);
                byte[] bytes = d.getData();
                String address = d.getAddress();
                String msg = new String(bytes);

                helloWorldTextField = new RichTextField("  Message text received : " + msg );
                add(helloWorldTextField);
            }
        }
        catch(Exception e){}

/* METHOD 2
        while(true)
        {
            try
            {
                DatagramConnection _dc = (DatagramConnection)Connector.open("sms://");
                Datagram d = _dc.newDatagram(_dc.getMaximumLength());
                _dc.receive(d);
                String address = new String(d.getAddress());
                String msg = new String(d.getData()); 

                helloWorldTextField = new RichTextField("Message received: " + msg + "\n" + address);
                add(helloWorldTextField);
                Alert.startVibrate(3000);
            }
            catch (IOException e)
            {
                    System.err.println(e.toString());
            }
        }
*/           

/*  METHOD 3
        try {
            MessageConnection _mc = (MessageConnection)Connector.open("sms://:0");

            for(;;)
            {
                Message m = _mc.receive();
                String address = m.getAddress();
                String msg = null;
                if ( m instanceof TextMessage )
                {
                    TextMessage tm = (TextMessage)m;
                    msg = tm.getPayloadText();
                }
                else if (m instanceof BinaryMessage) {

                    StringBuffer buf = new StringBuffer();
                    byte[] data = ((BinaryMessage) m).getPayloadData();
                    // convert Binary Data to Text
                    msg = new String(data, "UTF-8");
                }
                else
                    System.out.println("Invalid Message Format");

                RichTextField helloWorldTextField = new RichTextField("Received SMS text from " + address + "\n" + msg);
                add(helloWorldTextField);
            }
    }
    catch (IOException e)
    {
            System.err.println(e.toString());
    }
*/
    }

/*  METHOD 4
        public void notifyIncomingMessage(MessageConnection conn) {
            RichTextField helloWorldTextField = new RichTextField("notifyIncomingMessage DEBUT");
            add(helloWorldTextField);                

            try {
                Message m = conn.receive();
                helloWorldTextField = new RichTextField("- Message recu");
                add(helloWorldTextField);                

                String address = m.getAddress();
                String msg = null;

                if ( m instanceof TextMessage )
                {
                    TextMessage tm = (TextMessage)m;
                    msg = tm.getPayloadText();
                }
                else if (m instanceof BinaryMessage) {
                    StringBuffer buf = new StringBuffer();
                    byte[] data = ((BinaryMessage) m).getPayloadData();

                    // convert Binary Data to Text
                    msg = new String(data, "UTF-8");
                }
                else
                    System.out.println("Invalid Message Format");

                helloWorldTextField = new RichTextField("- Message de : " + address + " // \""+ msg + "\"");
                add(helloWorldTextField);
            }
            catch (IOException e) {
                helloWorldTextField = new RichTextField("erreur _mc.receive : " + e);
                add(helloWorldTextField);
            }

        }
*/

/*  METHOD 5
        public void notifyIncomingMessage(MessageConnection messageConnection)
        {
            new Thread()
            {
                MessageConnection conn;
                Thread set(MessageConnection conn)
                {
                    this.conn = conn;
                    return (this);
                }
                public void run()
                {
                    try
                    {
                        Message m = conn.receive();
                        String msg = null;

                        if ( m instanceof TextMessage)
                        {
                            TextMessage tm = (TextMessage) m;
                            msg = tm.getPayloadText();

                            RichTextField helloWorldTextField = new RichTextField("- Message de : " + m.getAddress() + " // \""+ msg + "\"");
                            this.add(helloWorldTextField);
                        }
                    }
                    catch (Exception e)
                    {
                    }
                }
            }.set(messageConnection).start();
        }
*/
}

In my code, I tested 5 methods. But, I think that all of them blocked the line where there is method of 'received() '.

If there is someone who can help me find my problem, it's going to be great. (Or if there is someone who wants to send me a complete code that works, it will be better than the grand )

Thank you for all the answers.

I agree with you. It's better if I post a solution.

I have re-written some other program that gets the phone number and the content of the incomming SMS.

Here is my code

public class smsReceived extends UiApplication
{
    private LabelField _status;
    private DatagramConnection _dc;

    public static void main(String[] args)
    {
        new smsReceived().enterEventDispatcher();
    }

    public smsReceived()
    {
        super();
        waitASms();
   }

    public void waitASms()
    {
        try
        {
            _dc = (DatagramConnection)Connector.open("sms://");
            for(;;)
            {
                Datagram d = _dc.newDatagram(_dc.getMaximumLength());
                _dc.receive(d);
                String address = new String(d.getAddress());
                String msg = new String(d.getData());
            }
        }
        catch (IOException e)
        {
            System.err.println(e.toString());
        }
    }
}

In this code, the string 'address' is the phone number and the string 'msg' is the content.

To view, please do another method with this channels.

Next time.

Tags: BlackBerry Developers

Similar Questions

  • How to listen only to the incoming sms message

    I want only to hear incoming sms do message not MMA, how.

    See this Article.

    http://www.BlackBerry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800563/What_Is...

    SMS to notify the application, look at this article.

    http://www.BlackBerry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800563/How_To _...

  • How to receive as net.rim.blackberry.api.mail.Message When listening for incoming sms?

    There are 3 types of ways to listen for incoming sms in the following link:

    http://www.BlackBerry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800563/What_Is...

    All those who receive the javax.wireless.messaging.Message for further processing.

    I need to check the priority of the message received, which is only available in net.rim.blackberry.api.mail.Message and not javax.wireless.messaging.Message.

    Can someone guide me to get the net.rim.blackberry.api.mail.Message When listening for incoming sms?

    Thank you.

    Net.rim.blackberry.api.mail.Message is actually for mails not for sms

    Press the button Bravo thank the user who has helped you.

    If your problem has been resolved then please mark the thread as "accepted Solution".

  • deleting incoming sms in the Inbox

    Anyone know how to remove sms all inbox.

    I can't find a solution in the API.

    Not that new look or sms outgoin.

    Never click on a URL from the tiny type that you never know where he's going to do. If you trust the site, never click on the links to the full URL:

    http://supportforums.BlackBerry.com/T5/Java-development/deleting-incoming-SMS-from-Inbox/TD-p/592620

    AndreyMM,

    He doesn't know the rest of the code. Try searching Google or even Crackberry post as they usually come from assets

  • Mark as read incoming sms

    OK, I could read/catch all incoming sms using a small piece of code but all these sms are also in the sms Inbox as unread.

    How can I mark as read?

    You cannot programmatically change the SMS Inbox.

  • How to program my incoming emails in descending order?

    I can't understand how to organize my incoming emails descending instead of the ascendant. Can someone help me with this?
    Don

    By clicking on a column header, which will be the primary sort column. Clicking the same header again will reverse the sort order. If you want to sort by date, click the DATE labeled header. Click on DATE for reverse sorting.

  • No incoming SMS sound heard

    Hello

    I have two iPhones one is version 5 and the second is 5 s version.

    Both are updated to the latest version of iOS.

    In my worm. 5 s when entering SMS comes the iPhone gives alert music.

    The problem is with another iPhone 5 that when entering SMS happens no sounds are heard.

    I tried to compare the configurations, but found no difference between the two.

    I have to lack the question.

    Where can I configure the iPhone 5 to produce music for the arrival of incoming SMS alert.

    Thank you

    I would add: no mute is on. It is not Nothing disturbs mode

    Try updating to the latest iOS

    Also try to put in a different sound for text in settings - sounds

    Force restart the phone and see if the SMS produced the new sound

  • How to detect a Variant empty?

    I get an error when my application passes a variant vacuum (as determined by the probe) to a variant of the function Data. The variant is a Global Variable that has not yet been initialized. I need to avoid calling the variant of the function of data as long as the variant is empty.

    How to detect that a variant is empty? I can't find a function or constant that will help me to do this.

    LabView 2010 is pretty inconsistent about how empty variables of different types are detected. How is there aren't any detection methods of vacuum for each type of data? Why are not always done in the same way?

    You can right click on one of the connectors on a service of alternative variants and select create constant.  This will create a small empty box of purple.  Then you can compare your Variant that and if it is empty, the comparison will be true.

  • How to detect the window closing event and to do some tasks before leaving

    Hello

    Someone knows how to detect the window closing event and to do some tasks before leaving?

    Sridhar

    Structure of the event allows to detect the window closing event. In the structure of the event,.

    Select this VI-> close round table for this task. See attached picture.

  • How to detect fraud sites on the net

    in fact, I came to know websites are offering you opportunities to earn money on the internet by clicking on the sites for example 'two Dollar click'. I want you please teach me how to detect its authentication and its evidence.

    Thank you

    The short answer is, "if it sounds too good to be true, it probably is." Any site that promises you money easy to 'make things you already all days' or 'just by ' is likely to be a scam waiting to be discovered.  The same goes for any flavor of 'Go this expensive piece of equipment for only a few dollars' or ' work from home and make thousands of dollars.

    There are dozens of these sites that go upwards and downwards and save it under a new name every day so it's really not anything to sure to check a site and determine if it is a scam or not.  Common sense is your best guide.  The only "secret: 'this scammer really knows how to separate a fool and his money access."

  • How to detect the sign of a number?

    I output which gives the number of negative or positive. My problem is how to detect the sign of the Boolean number and output? For example if the input number is negative as - 23.11 I want to output the value false and if the number is positive as 17.99 I want to output true.

    T H A N K S!

    Test if the number is greater than or equal zero.

  • How to detect if RTEXE is running on the controller RT SMU-8133

    Hello

    I need to know my PC if some executables RT runs on the remote computer RT (SMU-8133).
    Y at - it anyway how to detect in LabVIEW, if an application is running in real time and possibly only one?

    Thank you very much.

    Martin

    The important point is that call a distance VI in this way, you assume that the VI is already in memory. In this case, you don't have to give a full path, just the name of the VI.

    Mike...

  • How to detect what causing my hard drive space increase?

    Hello

    My space on the hard disk increases daily 100 MB how to detect the causes of this increase in my hard drive.

    Thanks for your help

    Hello

    My space on the hard disk increases daily 100 MB how to detect the causes of this increase in my hard drive.

    Thanks for your help

    Can be any number of things.  One possibility is the restoration of the system, which, by default, uses up to 12% of your hard drive.  An older version of Zone Alarm (6.5) creates very large files which have been followed by SR (http://bertk.mvps.org/html/tips.html#16 ).  In general, the default should be changed so that the space allocated to the SR should be limited to 1 GB (seehttp://bertk.mvps.org/html/diskspace.html ).

    Rather just guessing, download and run (free) JDiskReport , allowing you to know what is too much space.  Once you know, after return to get advice on how to deal with it.

  • How to detect an internet connection?

    How we detect that there is a connection?

    Have you tried hasDataCoverage? Should do what you need.

    https://bdsc.webapps.BlackBerry.com/HTML5/APIs/BlackBerry.System.html#.hasDataCoverage

  • How to detect if Bis - B is by carrier or Wi - Fi by programming

    How to detect if the BIS data traffic is routed via the operator network or Wi - Fi. Looking logo BB points, we can see that it will be close to seeing Wi - Fi if data are routed via Wi - Fi and close to the signal indicator carrier if the data is routed via the data network of the carrier.

    Is there a way to detect that programmatically?

    No, I don't know a way to affect the transport, so I would say turn off wifi would be the only solution.

Maybe you are looking for