每当我点击我的应用中的按钮时,我都会尝试向我的电话号码发送消息。应用说“消息成功发送”,但我没有得到任何短信。我不确定我的电话号码格式或我的smsmanager功能是不正确的。这是我的代码。任何帮助将是欣赏。谢谢。
public void sendSmsByManager() {
try {
// Get the default instance of the SmsManager
SmsManager smsManager = SmsManager.getDefault();
PendingIntent sentPI;
String SENT = "SMS_SENT";
sentPI = PendingIntent.getBroadcast(this, 0,new Intent(SENT), 0);
//phone number format is Malaysia +60134567891
smsManager.sendTextMessage(phoneNumber.getText().toString(),
null,
smsBody.getText().toString(),
sentPI,
null);
Toast.makeText(getApplicationContext(), "Your sms has successfully sent!",
Toast.LENGTH_LONG).show();
} catch (Exception ex) {
Toast.makeText(getApplicationContext(),"Your sms has failed...",
Toast.LENGTH_LONG).show();
ex.printStackTrace();
}
}