BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 11-27-2007, 12:54 AM   #1 (permalink)
Thumbs Must Hurt
 
Join Date: Oct 2007
Location: chennai.india
Model: 8100
PIN: N/A
Carrier: airtel
Posts: 57
Post Thanks: 0
Thanked 0 Times in 0 Posts
Arrow Receive sms using cldc application

Please Login to Remove!

my application wont receive my sms all messages came my inbox i defined port 0

private static class ListeningThread extends Thread {
private boolean _stop = false;
private DatagramConnection _dc;

public synchronized void stop()
{
_stop = true;
try
{
_dc.close(); // Close the connection so the thread returns.
} catch (IOException e) {
System.err.println(e.toString());
}
}

public void run() {
try
{
_dc = (DatagramConnection)Connector.open("sms://0");
for(;;) {
if ( _stop ) {
return;
}
Datagram d = _dc.newDatagram(_dc.getMaximumLength());
_dc.receive(d);
String address = new
String(d.getAddress());
String msg = new String(d.getData());
System.out.println("Message received: " + msg);
System.out.println("From: " + address);
System.exit(0);
}
} catch (IOException e) {
System.err.println(e.toString());
}
}
}
__________________
thanx n regards
jeyaprakash.c
Offline  
Old 11-27-2007, 03:33 AM   #2 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

did you try it without the 0? My (working) code is identical except
Code:
 _dc = (DatagramConnectionBase)Connector.open("sms://");
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 11-27-2007, 04:06 AM   #3 (permalink)
Thumbs Must Hurt
 
Join Date: Oct 2007
Location: chennai.india
Model: 8100
PIN: N/A
Carrier: airtel
Posts: 57
Post Thanks: 0
Thanked 0 Times in 0 Posts
Arrow Receving sms using cldc application

yes i tried but not working. my code is in below
Code:
import net.rim.device.api.io.*;
import net.rim.device.api.system.*;
import javax.microedition.io.*;
import java.util.*;
import java.io.*;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.BasicEditField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;

import net.rim.device.api.ui.container.VerticalFieldManager;

public class ReceiveSms extends UiApplication {
    private ListeningThread _listener;
    
    
// Additional code required for complete sample.
    public static void main(String[] args) {
        new ReceiveSms().enterEventDispatcher();
    }
    ReceiveSms() {
        _listener = new ListeningThread();
        _listener.start();
        Recive screen=new Recive();
        
        
        
        pushScreen(screen);
        
        
    }
    class Recive extends  MainScreen{
        Recive(){
            HorizontalFieldManager hManager = new HorizontalFieldManager();
            LabelField lab=new LabelField("Recive");
            BasicEditField edit=new BasicEditField("","");
            add(lab);
            add(edit);
            add(hManager);
            
        }
        
    }
    
    
    private static class ListeningThread extends Thread {
        private boolean _stop = false;
        private DatagramConnection _dc;
        
        private String address;
        
        private String msg;
        public synchronized void stop() {
            _stop = true;
            try {
                _dc.close(); // Close the connection so the thread returns.
            } catch (IOException e) {
                System.err.println(e.toString());
            }
        }
        public void run() {
            try {
                _dc = (DatagramConnection)Connector.open("sms://");
                for(;;) {
                    if ( _stop ) {
                        return;
                    }
                    Datagram d = _dc.newDatagram(_dc.getMaximumLength());
                    _dc.receive(d);
                    address = new String(d.getData());
                    msg = new String(d.getData());
                    Dialog.alert(address+msg);
                }
            } catch (IOException e) {
                
                
                System.err.println(e.toString());
            }
        }
    }
   
}
__________________
thanx n regards
jeyaprakash.c
Offline  
Old 11-28-2007, 05:28 PM   #4 (permalink)
Thumbs Must Hurt
 
Spartan115's Avatar
 
Join Date: Aug 2007
Model: Pearl
PIN: N/A
Carrier: T-Mobile
Posts: 80
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Sms

Wait I thought it was impossible to listen for SMS that's going into the inbox of the phone, you can only listen to a specific port.
Offline  
Old 11-29-2007, 06:51 AM   #5 (permalink)
New Member
 
Join Date: Nov 2007
Model: 8310
PIN: N/A
Carrier: vodafone
Posts: 1
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Port 0 reserved

Hi,
You cant listen to port 0, since it was reserved. Try some other port.
All the messages wil defaultly goes to port 0(if port is not specified). So u need to listen to some other port

Regards,
sridhar
Offline  
Old 11-29-2007, 07:18 AM   #6 (permalink)
Thumbs Must Hurt
 
Join Date: Oct 2007
Location: chennai.india
Model: 8100
PIN: N/A
Carrier: airtel
Posts: 57
Post Thanks: 0
Thanked 0 Times in 0 Posts
Arrow

hi srithar,

but somebody told its posiable to receive messages using port 0 see this links
1:Disclaimer
2:Disclaimer
__________________
thanx n regards
jeyaprakash.c

Last edited by jeyaprakash.c : 11-29-2007 at 07:48 AM.
Offline  
Old 11-29-2007, 08:16 AM   #7 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

this is out of one of my applications, the product page can be found here
put it into a thread and you should be good to go

Code:
_dc = (DatagramConnectionBase)Connector.open("sms://");
while (!stop) {
Datagram d = _dc.newDatagram(_dc.getMaximumLength());
 _dc.receive(d);
String address = d.getAddress();
String msg = new String(d.getData());
//do something with the received data here
}
_dc.close();
regarding your linked posts: You were told twice not to use port 0

hth,
simon
__________________
java developer, Devinto, hamburg/germany
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.