如何通过短信在TextView中发送文本?

时间:2013-01-03 16:43:07

标签: android sms

我用笑话改进我的应用程序,我有问题。我想添加“send by sms button”,我想通过TextViewSMS中发送文字(如果用户选择了笑话,他希望通过SMS发送)。

我该怎么做?

2 个答案:

答案 0 :(得分:1)

1。在您的应用程序内集成SMS Manager

在清单文件中添加权限::

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

 sendMySmsBtn=(Button)findViewById(R.id.send);
 sendMySmsBtn.setonclickListener(new OnClickListener(){
 public void Onclick()
   {
    sendSMS("99999999999", "message");
   });


  private void sendSMS(String phoneNumber, String message)
   {        
    SmsManager sms = SmsManager.getDefault();
    sms.sendTextMessage(phoneNumber, null, message,null, null);        
   }  

2。意图在您的设备中安装SMS应用程序

  int phoneNumber=9999999999; 
  Intent startSmsApp=new Intent(Intent.ACTION_VIEW, Uri.parse("sms:"
                    + phoneNumber);
  startSmsApp.putExtra("sms_body", message);
  startActivity(startSmsApp);

答案 1 :(得分:-1)

Send SMS in android。无法自动发送文本,Android安全功能。此代码将启动对SMS发送应用程序的Intent:

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("sms:"
                        + phoneNumber)));

另见this tutorialthis tutorial

相关问题