1 Reply Latest reply: Aug 17, 2011 9:13 AM by Darryl Burke RSS

    Problem with Receive SMS in WindowsMobile

    882812
      this is part of my code in MIDlet Class:
      -------------------------------------------------------
      public class MIDletName extends MIDlet implements MessageListener{
      
      private MessageConnection notifyCon;
      
      public  Constructor()
          {
              
          }
      
      public void pauseApp()
          {
              
              notifyPaused();
          }
      
      public void destroyApp(boolean unconditional)
          {
              try
              {
                  if(notifyCon != null)
                  {
                      this.notifyCon.setMessageListener(null);
                      this.notifyCon.close();
                  }
                //return;
              }
              catch (IOException ioex)
              {
                  
              }
              finally
              {
                  notifyCon = null;
              }
              System.gc();
              notifyDestroyed();
          }
      
          public void notifyIncomingMessage(/*final */MessageConnection MCon)
          {
              if(MCon == notifyCon)
              {
                  isNotify = true;
                  new PortListener(this);
              }
          }
      
          public void PortListener()
          {
              try
              {
                  if(notifyCon == null)
                      (notifyCon = (MessageConnection)Connector.open("sms://:16177")).setMessageListener(this);
                  return;
              }
              catch(IOException e)
              {
              }
          }
      
      public MessageConnection outNotifyCon()
          {
              return this.notifyCon;
          }  
      -------------------------------------------------------
      and this is PortListener class:
      -------------------------------------------------------
      public final class PortListener implements Runnable
      {
          private Thread trd = null;
          private MessageConnection notifyCon;
          private static MIDletName middd= null;
      
          public PortListener(MIDletName midparam)
          {
              middd= midparam;
              this.notifyCon = midparam.outNotifyCon();
              try
              {
                  if(trd == null)
                  {
                      trd = new Thread(this);
                      trd.start();
                  }
              }
              catch(Error er)
              {}
              MIDletName.isNotify = false;//isNotify is static,so access direct to it.otherwise,warning
      
      public void messageReceivedHandler()
          {
              String receivedMessage = "";
              try
              {
                  Message RealCon;
                  if((RealCon = notifyCon.receive()) != null)
                  {
                              if ((RealCon instanceof TextMessage))
                              {
                                  receivedMessage = ((TextMessage)RealCon).getPayloadText();
                              }
      ...
                  }
      
      
      public void run()
          {
              try
              {
                  synchronized(middd)
                  {
                      messageReceivedHandler();
                  }
              }
              finally
              {
                  this.trd = null;
              }
          }  
      -------------------------------------------------------
      there is no problem in java based mobiles.i have problem in WindowsMobiles

      i test this JAR in HTC Touch2 t3333(windows moblie 6.5) & HTC Cruise ( ? ).
      with Esmertec Jbed 20090506.2.1 by Aqrab MIDletManager.

      but i receive messages in inbox(not App).

      by the way,in some day,i change part of code,:
      -------------------------------------------------------
      public void pauseApp()
          {
              
              notifyPaused();
          }  
      -------------------------------------------------------
      to this:
      -------------------------------------------------------
      public void pauseApp()
          {
              notifyIncomingMessage(notifyCon)
              notifyPaused();
          }  
      -------------------------------------------------------
      and after that,i receive anyMessage,form Any Senders in my App!
      i unistall it,and after some days,i install it again,but its not work!!!!

      i test these ways to install MIDlet managers:
      1-bluetooth CAB file
      2-trasnfer CAb to mobile by ActiveSync
      but there is no different!

      1-how can i receive messages in my app,in WindowsMobile too?
      2- these code snippeds are true ever?!

      i see some another snipped code for listening,like this :
      -------------------------------------------------------
      int i;
              MessageConnection con;
              String[] conList;
      
              if ((conList = PushRegistry.listConnections(true)).length != 0)
                  for (i = conList.length - 1; i >= 0; i--)
                      try
                      {
                        (con = (MessageConnection)Connector.open(conList)).setMessageListener(this);
      this.conz.addElement(con);
      }
      catch (SecurityException sex)
      {
      }
      catch (IOException ioex)
      {

      }
      else
      for (i = (conList = PushRegistry.listConnections(false)).length - 1; i >= 0; i--)
      try
      {
      (con = (MessageConnection)Connector.open(conList[i])).setMessageListener(this);
      this.conz.addElement(con);
      }
      catch (SecurityException sex)
      {
      }
      catch (IOException ioex)
      {

      }

      -------------------------------------------------------
      and these for destryApp() :
      -------------------------------------------------------
      if (prtl.conz != null) // prtl is instanse of PortListener ( above code )
            while (!prtl.conz.isEmpty())
            {
              MessageConnection temp;
              if (( temp = (MessageConnection)prtl.conz.firstElement()) != null)
                try
                {
                  temp.setMessageListener(null);
                  temp.close();
                }
                catch (Exception ex)
                {
                }
              this.prtl.conz.removeElementAt(0);
            }
      -------------------------------------------------------
      whats different between these with my code that i said,and listen to port in 1 line! :
      -------------------------------------------------------
      public void PortListener()
          {
              try
              {
                  if(notifyCon == null)
                      (notifyCon = (MessageConnection)Connector.open("sms://:16177")).setMessageListener(this);
                  return;
              }
              catch(IOException e)
              {
              }
          }
      -------------------------------------------------------
      3-whats range of sopported ports in WindoesMobile?