BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 02-24-2010, 02:18 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:

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);



}

});


}





}



m not getting any prob with the code....its that , that i dont know how to run this code...i hope somebody can help me with this and yeah i know JDE and eclipse part so please skip it..just the way the flow goes in bberry when we run it....thanking in anticipation....
Offline  
Old 02-24-2010, 09:03 AM   #2 (permalink)
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Post Thanks: 20
Thanked 77 Times in 68 Posts
Default

Yuck! What a mess. You don't really expect people to wade through that to be able to help you with "...the way the flow goes..." do you?

Please read this: How to paste 100% FORMATTED Source Code In Your Forum Posts and try again.
__________________
My other Blackberry is a PlayBook.
Offline  




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