Android -- 短信

简介:

背景                                                                                          

image

主要代码                                                                                     

发送按钮的监听器:

复制代码
phone_number_editText = (EditText) findViewById(R.id.phone_number_editText);
        sms_content_editText = (EditText) findViewById(R.id.sms_content_editText);
        send_sms_button = (Button) findViewById(R.id.send_sms_button);
        
        send_sms_button.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
            String phone_number = phone_number_editText.getText().toString().trim();
            String sms_content = sms_content_editText.getText().toString().trim();
                if(phone_number.equals("")) {
                   Toast.makeText(MainActivity.this, “No”, Toast.LENGTH_LONG).show();
                } else {
                    SmsManager smsManager = SmsManager.getDefault();
                    if(sms_content.length() > 70) {
                        List<String> contents = smsManager.divideMessage(sms_content);
                        for(String sms : contents) {
                      smsManager.sendTextMessage(phone_number, null, sms, null, null);
                        }
                    } else {
               smsManager.sendTextMessage(phone_number, null, sms_content, null, null);
                    }
                    Toast.makeText(MainActivity.this,"OK", Toast.LENGTH_SHORT).show();
                }
            }     
        });
复制代码

权限:

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

我是天王盖地虎的分割线                                                               

这个因为觉得还是很简单的,就木有源码哈。

 




本文转自我爱物联网博客园博客,原文链接:http://www.cnblogs.com/yydcdut/p/3735243.html,如需转载请自行联系原作者

相关文章
|
存储 API Android开发
Android接收短信-createFromPdu
Android接收短信-createFromPdu
149 0
Android--短信拦截及IP拨号
版权声明:本文为博主原创文章,转载请标明出处。 https://blog.csdn.net/chaoyu168/article/details/51025730 public ...
889 0