попробуйте следующим образом
В файле AndroidManifest.xml добавьте следующие разрешения:
(android.permission.RECEIVE_SMS
)
(android.permission.SEND_SMS
)
// Demo source code to sends an SMS and notify status
private void send(String number, String message)
{
// notify when the SMS has been sent
registerReceiver(new BroadcastReceiver(){
@Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode())
{
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "Sent!",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
Toast.makeText(getBaseContext(), "GENERIC_FAILURE!",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
Toast.makeText(getBaseContext(), "RADIO_OFF!",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
Toast.makeText(getBaseContext(), "ERROR_NULL_PDU!",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
Toast.makeText(getBaseContext(), "ERROR_NO_SERVICE!",
Toast.LENGTH_SHORT).show();
break;
}
}
}, new IntentFilter("SMS_SENT"));
// notify when the SMS has been delivered
registerReceiver(new BroadcastReceiver(){
@Override
public void onReceive(Context arg1, Intent arg2) {
switch (getResultCode())
{
case Activity.RESULT_CANCELED:
Toast.makeText(getBaseContext(), "Not delivered",
Toast.LENGTH_SHORT).show();
break;
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "Delivered",
Toast.LENGTH_SHORT).show();
break;
}
}
}, new IntentFilter("SMS_DELIVERED"));
PendingIntent sentPendingIntent = PendingIntent.getBroadcast(this, 0,
new Intent("SMS_SENT"), 0);
PendingIntent deliveredPendingIntent = PendingIntent.getBroadcast(this, 0,
new Intent("SMS_DELIVERED"), 0);
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(number, null, message, sentPendingIntent, deliveredPendingIntent);
}