2011-04-26 21 views
7

Quiero abrir la aplicación nativa para enviar sms pero ya debe haber un número de teléfono. He encontrado ACTION_SEND pero cuando estoy llamando a mi función de TI de error de retorno que:ACTION_SEND usado para enviar sms

04-26 11:59:15.991: ERROR/AndroidRuntime(20198): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SENDTO (has extras) } 

Mi código presentado aquí:

private void smsSend(String number) { 
    Intent intent = new Intent(Intent.ACTION_SENDTO, null); 
    intent.putExtra(Intent.EXTRA_PHONE_NUMBER, number); 
    startActivity(intent); 
} 

Sé que es es simple, pero no sé por qué no lo hace trabajo y no puedo encontrar ninguna información completa.

Gracias por cualquier consejo.

Respuesta

40

Por qué, esto debería funcionar bien. http://developer.android.com/reference/android/content/Intent.html#ACTION_SENDTO

Compruebe hacia fuera mi código:

Uri uri = Uri.parse("smsto:0800000123"); 
Intent it = new Intent(Intent.ACTION_SENDTO, uri); 
it.putExtra("sms_body", "The SMS text"); 
startActivity(it); 
+0

Al usar Uri con el problema smsto resuelto;) – Robert

+2

Uri uri = Uri.parse ("smsto:"); para abrir mensajes que no se envían automáticamente a ningún número –

+0

OMG, eso es más o menos de necroposting, @mostafahashim – Lonkly

1

creo que debería utilizar el siguiente código:

Intent sendIntent = new Intent(Intent.ACTION_VIEW); 

//use to fill the sms body 
StringBuilder uri = new StringBuilder("sms:" + mobilenumber); 
sendIntent.putExtra("sms_body", ""); 
sendIntent.setType("vnd.android-dir/mms-sms"); 
sendIntent.setData(""); 
startActivity(sendIntent); 

creo que esto puede ayudar.

1

¡Gracias por la información! Aquí está mi solución usando la información anterior:

 
if (url.indexOf("tel:") > -1) { 
    startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse(url))); 
    return true; 
} 
else if (url.indexOf("sms:") > -1){ 
    startActivity(new Intent(Intent.ACTION_SENDTO, Uri.parse(url))); 
    return true; 
} 

Saludos.

Cuestiones relacionadas