短信发送器的实现
来源:互联网 发布:全民突击刷枪内购软件 编辑:程序博客网 时间:2024/05/20 01:47
1.新建名为sendsms项目
2.Activity_sms.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="${relativePackage}.${activityClass}" > <TextView android:id="@+id/tvphone" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/tip_phone" /> <EditText android:id="@+id/etphone" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/tvphone" android:inputType="phone" /> <TextView android:id="@+id/tvsms" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/etphone" android:text="@string/tip_sms" /> <!-- 作业思考 怎么实现自动换行的效果 --> <EditText android:id="@+id/etsms" android:layout_width="match_parent" android:layout_height="100dp" android:gravity="top" android:layout_below="@+id/tvsms" android:inputType="textMultiLine" /> <Button android:id="@+id/sendBtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/etsms" android:text="@string/tip_send" /></RelativeLayout>字符串资源:<?xml version="1.0" encoding="utf-8"?><resources> <string name="app_name">sendsms</string> <string name="hello_world">Hello world!</string> <!-- 准备字符串的资源 --> <string name="tip_phone">请输入电话号码</string> <string name="tip_sms">请输入发送的信息</string> <string name="tip_send">发送</string></resources>
3.SmsActivity.java
package com.example.sendsms;import java.util.List;import android.app.Activity;import android.os.Bundle;import android.telephony.SmsManager;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.EditText;import android.widget.Toast;public class SmsActivity extends Activity { private Button sendBtn; private EditText etphone,etsms; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 设置显示的视图 setContentView(R.layout.activity_sms); // 获取点击发送按钮的控件对象 sendBtn = (Button) findViewById(R.id.sendBtn); //获取电话号码的控件对象 etphone=(EditText) findViewById(R.id.etphone); //获取要发送信息的控件对象 etsms = (EditText) findViewById(R.id.etsms); // 注册按钮的点击事件 sendBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //1.获取电话号码及发送的短信内容 String phone = etphone.getText().toString(); String content = etsms.getText().toString(); //2.发短信的管理器对象 SmsManager smsManager = SmsManager.getDefault(); //3.拆分短信内容 List<String> list = smsManager.divideMessage(content); //4.遍历发送信息 for(String sms:list){ //5.逐条发送短信 smsManager.sendTextMessage(phone, null, sms, null, null); } //5.提示短信发送成功 Toast.makeText(SmsActivity.this, "发短信成功", Toast.LENGTH_LONG).show(); } }); }}/** * 1.添加发送短信的权限 * 2.获取发送短信管理器对象 * 3.执行发送操作(自动拆分70字符 160) * */
4.在AndroidManifest.xml中添加发短信的权限
<!-- 发送短信的权限 --> <uses-permission android:name="android.permission.SEND_SMS"/>
4 0
- 短信发送器的实现
- Android 短信发送器的实现
- Android 短信发送器的实现
- Android短信发送器的实现
- android-短信发送器的实现
- 短信发送器的简单实现
- Android实现短信发送器
- Android8下一个简单短信发送器的实现
- Android开发系列(二):短信发送器的实现
- 短信发送器的详解
- Android - 批量发送短信的实现方式
- android实现发送短信的功能
- PHP实现 手机发送短信的程序
- android后台发送短信的实现
- Swift - 短信发送功能的实现
- Swift - 实现发送短信的功能
- 发送短信验证码按钮的实现
- Android实现发送短信的功能
- 恢复git reset后的commit
- 【Java语言】如何提高Java程序性能?
- 确定主机字节序
- 【C语言】检测malloc最大能分配多少空间。
- EL表达式在js文件中使用
- 短信发送器的实现
- 黑马程序员-----Java基础-----I/O流操作
- 子类继承父类的私有属性
- 关于王垠和Lisp的感悟
- 求最大子数组的和(动态规划法)
- Codeforces Round #302 (Div. 1) A. Writing Code
- 总结自己的Git常用命令
- android的单元调试
- 欢迎使用CSDN-markdown编辑器