这将对您有效:
public void sendSmsByManager() {
try {
//If the SMS Contains the WORD MYSELF Prompt the User If they Want to send the SMS
if (smsBody.getText().toString().contains("MYSELF")){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("SMS CONTAINS MYSELF! Do you really Want to send this SMS"); // It will set the message you want to display
builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Get the default instance of the SmsManager
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNumber.getText().toString(),
null,
smsBody.getText().toString(),
null,
null);
Toast.makeText(getApplicationContext(),
"Your sms has successfully sent!",
Toast.LENGTH_LONG).show();
}
});
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
} catch (Exception ex) {
Toast.makeText(getApplicationContext(), "Your sms has failed...",
Toast.LENGTH_LONG).show();
ex.printStackTrace();
}
}