【问题标题】:Android - Send SMS through the built-in SMS applicationAndroid - 通过内置短信应用程序发送短信
【发布时间】:2012-05-04 03:37:44
【问题描述】:

首先,我使用模拟器进行测试。 我想使用消息文本(作为参数发送)打开默认 SMS 应用程序,并允许用户从那里获得控制权(以及内置应用程序)。 我使用此代码:

Button btnSMS = (Button) findViewById(R.id.btnSMS);
    btnSMS.setOnClickListener(new View.OnClickListener() {
        public void onClick(View arg0) {
            Intent it = new Intent(Intent.ACTION_VIEW); 
            it.putExtra("sms_body", "text"); 
            it.setType("vnd.android-dir/mms-sms");
        }
    });

当我按下按钮时,没有任何反应。我希望 SMS 默认应用程序会打开,其中包含用户必须填写的文本和其他字段,然后发送消息。这是因为模拟器还是我的代码?我还在清单中指定了权限:

【问题讨论】:

    标签: android sms default


    【解决方案1】:

    使用内置短信应用发送短信:

    Intent i = new Intent(android.content.Intent.ACTION_VIEW);
    
    i.putExtra("address", "09090909; 092322424; 123456778");
    
    i.putExtra("sms_body", "SMS Content");
    
    i.setType("vnd.android-dir/mms-sms");
    
    startActivity(i);
    

    【讨论】:

      【解决方案2】:

      你缺少 startActivity::

      Intent it = new Intent(Intent.ACTION_VIEW); 
      it.putExtra("sms_body", "text"); 
      it.setType("vnd.android-dir/mms-sms");
      startActivity(it);
      

      或者你也可以使用下面的代码::

      String number = "12346556";  // The number on which you want to send SMS  
      startActivity(new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms", number, null)));
      

      【讨论】:

      • 我脑子里乱七八糟的!谢谢!
      猜你喜欢
      • 1970-01-01
      • 2016-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多