BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 02-24-2010, 02:12 AM   #1 (permalink)
Knows Where the Search Button Is
 
Join Date: Feb 2010
Model: 7100t
PIN: N/A
Carrier: VODAFONE
Posts: 18
Post Thanks: 0
Thanked 0 Times in 0 Posts
Smile sms retrieval problems::::The prob. i've been getting is there is no error generated

Please Login to Remove!

public final class GUILessApp extends Application implements javax.wireless.messaging.MessageListener
{
private BackGroundApp backGroundApp;
public static void main(String[] args)
{
GUILessApp theApp = new GUILessApp();
theApp.enterEventDispatcher();
}

public GUILessApp()
{
//Creates and starts a new BackGroundApp thread.

backGroundApp = new BackGroundApp();
backGroundApp.start();
}

//The thread that will run in the background.
private class BackGroundApp extends Thread
{


boolean stopThread = false;
public synchronized void stop()
{
stopThread = true;
}

public void run()
{
while (!stopThread)
{

System.out.println("Application is running");


try
{

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

for(;;)
{
Datagram d = _dc.newDatagram(_dc.getMaximumLength());
_dc.receive(d);
byte[] bytes = d.getData();
String address = d.getAddress();
String msg = new String(bytes);
System.out.println( "Received SMS text from " + address + " : " + msg);
}
}
catch (Exception e) {

}

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");
System.out.println("Received SMS text from " + address + " : " + msg);
}


}
catch (Exception e)
{
//Exception handling would go here.
}
}
}
}





//Stop the thread on exit.
protected void onExit()
{
backGroundApp.stop();
}
MessageConnection _mc1;
Message m;
public void notifyIncomingMessage(MessageConnection conn)

{
//final MessageConnection _mc1;
try {
_mc1 = (MessageConnection)Connector.open("sms://:0");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
_mc1.setMessageListener(this);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
UiApplication.getApplication().invokeLater(new Runnable()
{
public void run()
{

try {
m = _mc1.receive();
} catch (InterruptedIOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
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
try {
msg = new String(data, "UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else
System.out.println("Invalid Message Format");
System.out.println("Received SMS text from " + address + " : " + msg);



}

});


}











}
Offline  
Old 02-24-2010, 07:28 AM   #2 (permalink)
BlackBerry Master
 
dankarlinski's Avatar
 
Join Date: May 2007
Model: 1
Carrier: 1
Posts: 3,391
Post Thanks: 1
Thanked 2 Times in 2 Posts
Default

Wirelessly posted (White and Nerdy)

There's no need to double post
Offline  
Old 02-25-2010, 12:11 AM   #3 (permalink)
Knows Where the Search Button Is
 
Join Date: Feb 2010
Model: 7100t
PIN: N/A
Carrier: VODAFONE
Posts: 18
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

actually m not sure where to delete the previous thread....and kinda messed up with this one...so postel a new one...anyways let me know how to get rid of this thread
Offline  




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