PDA

View Full Version : مشکل در javax.wireless.messaging



Parthia
سه شنبه 26 شهریور 1387, 08:42 صبح
سلام دوستان
میخواستم ببینم این کد برای ارسال و دریافت اس ام اس چه مشکلی داره
(ارسالش درست انجام میشه ولی دریافتش نمیشه نمیدونم چرا)
در ضمن اگر کسی هم بلده چطور از شر این Permission ها راحت بشیم یه ندا بده دمتون گرم!!!


package App;
//Author : Morteza Sherafati (mortie.sh@gmail.com)
//A Class To Manage Text Messages (SMS) in Micro Devices (J2ME)
import javax.microedition.io.Connector;
import javax.wireless.messaging.*;
public class SMS implements MessageListener
{
private final String smsProtocol = "sms://";
private MessageConnection connection;
private TextMessage outTM;
private String outNum;
private String inNum;
private TextMessage inTM;

SMS()
{
try
{
connection = (MessageConnection)Connector.open(smsProtocol+":5000");
connection.setMessageListener(this);
}
catch(Exception e)
{}
}

public boolean sendSMS(String phoneNum,String textMSG)
{
outNum = phoneNum;
try
{
connection = (MessageConnection)Connector.open(smsProtocol+outN um);
outTM = (TextMessage)connection.newMessage(connection.TEXT _MESSAGE);
outTM.setPayloadText(textMSG);
connection.send(outTM);
return true;
}
catch(Exception e)
{return false;}
}
public void notifyIncomingMessage(MessageConnection conn) {
connection = conn;
try
{
inTM = (TextMessage)connection.receive();
}
catch(Exception e)
{}
}

public String getSMS()
{
if (isNew())
return "error";
else
return inTM.getPayloadText();
}

public String getNum()
{
if (isNew())
return "error";
else
{
inNum = inTM.getAddress().substring(6,inTM.getAddress().le ngth());
return inNum;
}
}

public void destroyNewSMS()
{
inTM = null;
}

public boolean isNew()
{
if (inTM == null)
return false;
else
return true;
}
}