No se pueden enviar SMS con SMSManager en Android

En mi aplicación no quiero usar el remitente de mensajes predeterminado. Para ello seguí el siguiente enlace En Android es posible enviar mensajes SMS a más de un destinatario en código?

Pero no está enviando sms.please me ayudan con cómo puedo enviar sms en android – he intentado seguir demasiado PendingIntent sentPI = PendingIntent.getBroadcast (esto, 0, nueva intención (ENVIADO), 0);

PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0, new Intent(DELIVERED), 0); SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI); 

Tampoco funciona.
SMSAPPActivity.java

EDIT:

 btnSendSMS.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String message = txtMessage.getText().toString(); String[] PhnNoArray = new String[2]; PhnNoArray[0] = "9999999999"; PhnNoArray[1] = "8888888888"; // StringTokenizer st = new StringTokenizer(phoneNo, ","); smsManager = SmsManager.getDefault(); for (int i = 0; i < PhnNoArray.length; i++) { smsManager = SmsManager.getDefault(); // this is the function that does all the magic // sms.sendTextMessage(phoneNumber, null, msg, pi, null); smsManager.sendTextMessage(PhnNoArray[i], null, message, null, null); Toast.makeText(getBaseContext(), "SMS sent : " + i, Toast.LENGTH_SHORT).show(); } } }); 

Por favor, vea la edición y decirme lo que he hecho wrong.tost está apareciendo pero sms no se recibe en otro teléfono mediante el uso de este código

He utilizado el siguiente código para enviar sms a varios números y sms enviado se guarda en los mensajes

 private void sendSMS(String phoneNumber, String message) { String SENT = "SMS_SENT"; String DELIVERED = "SMS_DELIVERED"; PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, new Intent( SENT), 0); PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0, new Intent(DELIVERED), 0); // ---when the SMS has been sent--- registerReceiver(new BroadcastReceiver() { @Override public void onReceive(Context arg0, Intent arg1) { switch (getResultCode()) { case Activity.RESULT_OK: ContentValues values = new ContentValues(); for (int i = 0; i < MobNumber.size() - 1; i++) { values.put("address", MobNumber.get(i).toString());// txtPhoneNo.getText().toString()); values.put("body", MessageText.getText().toString()); } getContentResolver().insert( Uri.parse("content://sms/sent"), values); Toast.makeText(getBaseContext(), "SMS 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_NO_SERVICE: Toast.makeText(getBaseContext(), "No service", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NULL_PDU: Toast.makeText(getBaseContext(), "Null PDU", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_RADIO_OFF: Toast.makeText(getBaseContext(), "Radio off", Toast.LENGTH_SHORT).show(); break; } } }, new IntentFilter(SENT)); // ---when the SMS has been delivered--- registerReceiver(new BroadcastReceiver() { @Override public void onReceive(Context arg0, Intent arg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS delivered", Toast.LENGTH_SHORT).show(); break; case Activity.RESULT_CANCELED: Toast.makeText(getBaseContext(), "SMS not delivered", Toast.LENGTH_SHORT).show(); break; } } }, new IntentFilter(DELIVERED)); SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI); } 

Para enviar el mensaje a los números múltiples que utilicé encima de la función como:

 if (MobNumber != null) { for (int i = 0; i < MobNumber.size(); i++) { String message = MessageText.getText().toString(); String tempMobileNumber = MobNumber.get(i).toString(); sendSMS(tempMobileNumber, message); } 

1) agrega mensajes en Sent en lugar de Outbox, ya que Outbox contiene mensajes que se supone que deben enviarse o enviar.

2) cuando usted envía el mensaje agreganlas al mismo tiempo en " content: // sms / send uri.

Lo que está deteniendo u para almacenarlos en la base de datos. Y lo que has probado todavía.

Use el código abajo para enviarSMS

  smsManager.sendTextMessage(number, null,desc, null, null); 

Y utilizando el contenido: // sms / URI enviado , puede insertar el mismo mensaje de texto en la base de datos de mensajes

Espero que esto le pueda ayudar.

MainActivity.java

 import android.os.Bundle; import android.app.Activity; import android.telephony.SmsManager; import android.view.Menu; import android.view.inputmethod.InputMethodManager; import android.widget.*; import android.view.View.OnClickListener; import android.view.*; public class MainActivity extends Activity implements OnClickListener{ Button click; EditText txt; TextView txtvw; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); click = (Button)findViewById(R.id.button); txt = (EditText)findViewById(R.id.editText); txtvw = (TextView)findViewById(R.id.textView1); click.setOnClickListener(this); } @Override public void onClick(View v){ txt.setText(""); v = this.getCurrentFocus(); try{ SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage("8017891398",null,"Sent from Android",null,null); } catch(Exception e){ txtvw.setText("Message not sent!"); } if(v != null){ InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(v.getWindowToken(),0); } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } 

Agrega esta línea en AndroidManifest.xml

 <uses-permission android:name="android.permission.SEND_SMS" /> 

Introduzca aquí la descripción de la imagen

Si usted está usando el dispositivo dual del sim entonces usted debe tener que mencionar el número del remitente, usted no puede pasar el null en ese momento. De lo contrario, SmsManager lanzará un error llamado SmsManager.RESULT_ERROR_GENERIC_FAILURE .

Código para comprobar los números de sims activos:

 public static int getNumberOfActiveSim(Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { SubscriptionManager subscriptionManager = SubscriptionManager.from(context); List<SubscriptionInfo> subscriptionInfo = subscriptionManager.getActiveSubscriptionInfoList(); return subscriptionInfo != null ? subscriptionInfo.size() : 0; } TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); if(telephonyManager != null && telephonyManager.getSimState() == TelephonyManager.SIM_STATE_ABSENT){ return 1; } return 0; } 

Simplemente enviarlo directamente … utilizando el SmsManager . El único problema es que el usuario no lo sabe.

En mi caso, era el hecho de que el cuerpo del mensaje excedió 160 caracteres y tuve que usar sendMultipartTextMessage en lugar de sendTextMessage .

  • Bloqueo de SMS y Permitir problema en android 4.4 (kitkat) versión
  • Detección de SMS entrantes y salientes
  • Volver a Actividad después de completar la acción en Android?
  • SMS recibidos en mi aplicación de SMS y en Hangouts, aunque llamo a abortBroadcast ()
  • Android: comparte texto sin formato con la intención (para todas las aplicaciones de mensajería)
  • ¿Cómo enviar SMS usando Twilio en mi aplicación Android?
  • Cómo obtener el número smsc de un teléfono en android?
  • Abortar / Cancelar transmisiones
  • El envío de SMS mediante Intent no incluye destinatarios en algunos dispositivos
  • SMS BroadCast Receptor recibe muchas veces?
  • Puedo enviar "SMS recibido intención"?
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.