我写了一段简易的发送短息程序,在两个模拟器中可能正常发送短信,但我部署到的手机(魅族M9)上时,短信发不出来,在AndroidManifest.xml配置文件也加上短信发送权限,我的手机没有欠费哦。具体代码如下,各位大虾帮忙看看
public void onClick(View v)
{
// TODO Auto-generated method stub
String smsNum = mEditText1.getText().toString();
String smsContent = mEditText2.getText().toString();
//建立一个发送短信的对象
SmsManager sms = SmsManager.getDefault();
//验证短信号码和短信内容
if (isPhoneNumberValid(smsNum))
{
try
{
PendingIntent mPI = PendingIntent.getBroadcast(Demo05_03.this, 0, new Intent(), 0);
ArrayList array=sms.divideMessage(smsContent); //拆分短信内容
for (int i=0;i<array.size();i++)
{
sms.sendTextMessage(smsNum, null, array.get(i).toString(), mPI, null);
}
}
catch(Exception e)
{
e.printStackTrace();
}
Toast.makeText(Demo05_03.this, "发送成功!", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText
(
Demo05_03.this,
"短信内容超过70字,请删除部分内容;或者号码格式错误!!",
Toast.LENGTH_SHORT
).show();
}
public void onClick(View v)
{
// TODO Auto-generated method stub
String smsNum = mEditText1.getText().toString();
String smsContent = mEditText2.getText().toString();
//建立一个发送短信的对象
SmsManager sms = SmsManager.getDefault();
//验证短信号码和短信内容
if (isPhoneNumberValid(smsNum))
{
try
{
PendingIntent mPI = PendingIntent.getBroadcast(Demo05_03.this, 0, new Intent(), 0);
ArrayList array=sms.divideMessage(smsContent); //拆分短信内容
for (int i=0;i<array.size();i++)
{
sms.sendTextMessage(smsNum, null, array.get(i).toString(), mPI, null);
}
}
catch(Exception e)
{
e.printStackTrace();
}
Toast.makeText(Demo05_03.this, "发送成功!", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText
(
Demo05_03.this,
"短信内容超过70字,请删除部分内容;或者号码格式错误!!",
Toast.LENGTH_SHORT
).show();
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货