代码是小马写的,我只是借来用用~(@^_^@)~
在此基础上可以实现以下功能:

  1. 发送特定指令到指定对象
  2. 实现短信群发
  3. 定时自动发送信息

SendSmsActivity.java:

package com.test.smsmangerdemo.sendsmsactivity;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.content.Intent;import android.app.PendingIntent;import android.telephony.SmsManager;import android.view.View;import android.widget.Button;import android.widget.EditText;import android.widget.Toast;/** *发送短信实例 */public class SendSmsActivity extends AppCompatActivity {    EditText phone, content;    Button send;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_send_sms);        //获取 SMSManger管理器        final SmsManager smsManager = SmsManager.getDefault();        //初始化控件        phone = (EditText) findViewById(R.id.et_phone);        content = (EditText) findViewById(R.id.et_content);        send = (Button) findViewById(R.id.btn_send);        send.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                //创建一个 android.app.PendingIntent 对象                PendingIntent pi = PendingIntent.getActivity(SendSmsActivity.this, 0, new Intent(), 0);                //发送短信                smsManager.sendTextMessage(phone.getText().toString(), null, content.getText().toString(),                        pi, null);                //提示短信发送完成                Toast.makeText(SendSmsActivity.this, "短信发送完成", Toast.LENGTH_SHORT).show();            }        });    }}

AndroidMainfest.xml:

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.test.smsmangerdemo.sendsmsactivity" >    <uses-permission android:name="android.permission.SEND_SMS"/>    <application        android:allowBackup="true"        android:icon="@mipmap/ic_launcher"        android:label="@string/app_name"        android:supportsRtl="true"        android:theme="@style/AppTheme" >        <activity android:name=".SendSmsActivity" >            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            intent-filter>        activity>    application>manifest>

activity_send_sms.xml:

<?xml version="1.0" encoding="utf-8"?> <LinearLayoutxmlns: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"android:orientation="vertical"tools:context="com.test.smsmangerdemo.sendsmsactivity.SendSmsActivity"><LinearLayout    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:orientation="horizontal">    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="收件人"/>    <EditText        android:id="@+id/et_phone"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_marginLeft="10dp"/>LinearLayout><LinearLayout    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:layout_marginTop="10dp"    android:orientation="horizontal">    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="发送内容"/>    <EditText        android:id="@+id/et_content"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_marginLeft="10dp"        android:gravity="top"        android:lines="5"        android:text="你好"/>LinearLayout><Button    android:layout_gravity="center_horizontal"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="发送"    android:id="@+id/btn_send"    />LinearLayout>

实现效果:

更多相关文章

  1. Android周报第二十四期
  2. Android(java)学习笔记80:UDP协议发送数据
  3. Android(安卓)BroadcastReceiver 简介
  4. android 检测网络或wifi是否开启
  5. android线程调度工具类SchedulerUtils
  6. Android为多媒体文件生成缩略图
  7. Android(安卓)四大组件之 Service(二)
  8. 【学习Android(安卓)NDK开发】native code通过JNI调用Java方法
  9. Java和Javascript互调的例子 ---------(Android(安卓)WebView 中)

随机推荐

  1. Android:网络编程及Internet应用
  2. Android(安卓)开源项目分类汇总(很全)
  3. android 下载图片到本地 sdcard
  4. Android(安卓)6.0 读写SD卡权限问题(续)
  5. [置顶] Android通过tcpdump抓包
  6. Android(安卓)ZoomControls放大缩小图片
  7. android 铃声设置流程讲解
  8. Android(安卓)Weekly Notes Issue #223
  9. Windows 7 部署 Android(安卓)开发环境傻
  10. android Menory 小结