android手机模拟器发短信问题 30
小弟最近在研究Android手机开发,在写了一个发短信的程序在AndroidManifest中已加入发送短信的权限,java代码如下publicclassTestSMSe...
小弟最近在研究Android手机开发,在写了一个发短信的程序在AndroidManifest中已加入发送短信的权限,java代码如下
public class TestSMS extends Activity {
Button btnSendSMS;
EditText txtPhoneNum;
EditText txtMessage;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnSendSMS=(Button)findViewById(R.id.btnSendSMS);
txtPhoneNum=(EditText)findViewById(R.id.txtPhoneNum);
txtMessage=(EditText)findViewById(R.id.txtMessage);
btnSendSMS.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
String phoneNo= txtPhoneNum.getText().toString();
String message= txtMessage.getText().toString();
if(phoneNo.length()>0&&message.length()>0)
sendSMS(phoneNo,message);
else
Toast.makeText(getBaseContext(), "Please enter phone numeber and message", Toast.LENGTH_SHORT).show();
}
});
}
private void sendSMS(String phoneNumber,String messages){
PendingIntent pi=PendingIntent.getActivity(this, 0, new Intent(this,TestSMS.class),0);
SmsManager sms=SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, messages, pi, null);
Toast.makeText(getBaseContext(), "短信已发出", Toast.LENGTH_SHORT).show();
}
但是在模拟器中通过端口号发送短信时另一个模拟器却收不到,而在系统中通过telnet却能收到,我对比了下网上有关的程序,都没什么差别,但是为什么收不到呢?希望高手给予解决 展开
public class TestSMS extends Activity {
Button btnSendSMS;
EditText txtPhoneNum;
EditText txtMessage;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnSendSMS=(Button)findViewById(R.id.btnSendSMS);
txtPhoneNum=(EditText)findViewById(R.id.txtPhoneNum);
txtMessage=(EditText)findViewById(R.id.txtMessage);
btnSendSMS.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
String phoneNo= txtPhoneNum.getText().toString();
String message= txtMessage.getText().toString();
if(phoneNo.length()>0&&message.length()>0)
sendSMS(phoneNo,message);
else
Toast.makeText(getBaseContext(), "Please enter phone numeber and message", Toast.LENGTH_SHORT).show();
}
});
}
private void sendSMS(String phoneNumber,String messages){
PendingIntent pi=PendingIntent.getActivity(this, 0, new Intent(this,TestSMS.class),0);
SmsManager sms=SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, messages, pi, null);
Toast.makeText(getBaseContext(), "短信已发出", Toast.LENGTH_SHORT).show();
}
但是在模拟器中通过端口号发送短信时另一个模拟器却收不到,而在系统中通过telnet却能收到,我对比了下网上有关的程序,都没什么差别,但是为什么收不到呢?希望高手给予解决 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询