"
PHP Code:
"
public final class GUILessApp extends Application implements javax.wireless.messaging.MessageListener
{
int flag=0;//just for the sake of diff. between msgs
SMSParameters sp=new SMSParameters();
int headerid; //header of the SMS recieved
int voiceid=SMSParameters.PROTOCOL_ID_VOICE; //Header value for VOice SMS
//public int getProtocolId(); returns the PROTOCOL_ID_VOICE; //REturns the SMS header ID (sms/voice)
private BackGroundApp backGroundApp;
public static void main(Stringxxx91;xxx93; args)
{
GUILessApp theApp = new GUILessApp();
theApp.enterEventDispatcher();
}
public GUILessApp()
{
//Creates and starts a new BackGroundApp thread.
backGroundApp = new BackGroundApp();
// System.out.print("reched bg grnd process");
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");
}
}
}
//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();
}
Application.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();
bytexxx91;xxx93; 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");
}
if( (headerid=(sp.getProtocolId()))== voiceid)
{
flag=1;
System.out.println("voice msg received" + address);
UiApplication.getUiApplication().pushScreen(new msgscreen(flag));
}
else
{
flag=0;
System.out.println("Received SMS text from " + address + " : " + msg);
UiApplication.getUiApplication().pushScreen(new msgscreen(flag));
}
}
});
}
}
"
"
do you see any problems with this...let me know..