2011-04-26 75 views
7

我想打开本机应用程序发送短信,但应该已经有电话号码。我发现ACTION_SEND但是当我打电话给我的功能,它的回报错误:ACTION_SEND用于发送短信

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) } 

我的代码这里介绍:

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

我知道这是很简单,但我不知道为什么它不工作,我找不到任何helfull信息。

感谢您的任何建议。

回答

40

为什么这应该很好。 http://developer.android.com/reference/android/content/Intent.html#ACTION_SENDTO

看看我的代码:

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

通过使用Uri和smsto问题解决了;) – Robert 2011-04-26 10:08:29

+2

Uri uri = Uri.parse(“smsto:”);只打开邮件不会自动发送到任何数字 – 2016-05-23 23:59:44

+0

OMG,这是相当多的necroposting,@mostafahashim – Lonkly 2016-05-24 13:52:34

1

我认为你应该使用下面的代码:

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); 

我觉得这可能会帮助你。

1

感谢您的信息! 下面是使用以前的信息我的解决方案:

 
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; 
} 

最好的问候。