【问题标题】:how can i set the Text Message by default when i start the SMS activity from my App?当我从我的应用程序启动 SMS 活动时,如何默认设置短信?
【发布时间】:2012-01-17 17:59:39
【问题描述】:
我从我的 Android 应用程序启动 默认 SMS 活动,以便使用以下代码发送 SMS:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("sms:"));
startActivity(intent);
但我想直接在我的EditText 中设置一些包含文本消息的文本(当我启动默认 SMS 活动时,EditText 为空)。我怎样才能做到这一点 ?
问候,
【问题讨论】:
标签:
android
android-intent
sms
【解决方案1】:
其实很简单。只需将sms_body 数据添加到意图
String messageBody = "This sms message"
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("sms:"));
intent.putExtra( "sms_body", messageBody );
startActivity(intent);
【解决方案2】:
此代码适用于我:
Intent smsIntent = new Intent(Intent.ACTION_VIEW);
smsIntent.setData(Uri.parse("sms:"));
smsIntent.putExtra("sms_body", "share text");
startActivity(smsIntent);