Android SmsManager(短信管理器),发送短信息

news/2024/7/4 12:54:38

AndroidManifest.xml

<uses-permission android:name="android.permission.SEND_SMS"/>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="shortcut.song.com.myapplication.SendSmsActivity">

    <EditText
        android:id="@+id/send_number"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <EditText
        android:id="@+id/send_msg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <Button
        android:id="@+id/btn_send"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Send"/>
</LinearLayout>
package shortcut.song.com.myapplication;

import android.app.PendingIntent;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
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 number, sendmsg;
    Button btnSend;
    SmsManager smsManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_send_sms);
        // 获取SmsManager
        smsManager = SmsManager.getDefault();

        number = (EditText)findViewById(R.id.send_number);
        sendmsg = (EditText)findViewById(R.id.send_msg);
        btnSend = (Button)findViewById(R.id.btn_send);

        btnSend.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 创建一个PendingIntent对象
                PendingIntent pi = PendingIntent.getActivity(SendSmsActivity.this, 0, new Intent(), 0);
                // 发送信息
                smsManager.sendTextMessage(number.getText().toString(), null, sendmsg.getText().toString(), pi, null);
                // 提示发送完成
                Toast.makeText(SendSmsActivity.this, "发送完成", Toast.LENGTH_SHORT).show();
            }
        });

    }
}

运行效果:

这里写图片描述


http://www.niftyadmin.cn/n/4308598.html

相关文章

分享一个LiteDB做的简单考试系统辅助工具

凌晨&#xff0c;被安排在公司值班&#xff0c;因为台风“灿鸿”即将登陆&#xff0c;风力太大&#xff0c;办公楼&#xff0c;车间等重要部分需要关注。所以无聊&#xff0c;那就分享一下&#xff0c;今天给朋友临时做的一个小的考试系统辅助工具吧。其实非常小&#xff0c;需…

Android SmsManager 短信群发

AndroidManifest.xml <uses-permission android:name"android.permission.READ_PHONE_STATE" /><uses-permission android:name"android.permission.SEND_SMS" /> list.xml <?xml version"1.0" encoding"UTF-8"?&g…

JavaScipt 源码解析 异步

我们常见的异步操作&#xff1a; 定时器setTimeout postmessage WebWorkor CSS3 动画 XMLHttpRequest HTML5的本地数据 等等… JavaScript要求在与服务器进行交互时要用异步通信&#xff0c;如同AJAX一样。因为是异步模型&#xff0c;所以在调用Transaction游览器提供的本地数据…

.NET平台开源项目速览(10)FluentValidation验证组件深入使用(二)

在上一篇文章&#xff1a;.NET平台开源项目速览(6)FluentValidation验证组件介绍与入门(一) 中&#xff0c;给大家初步介绍了一下FluentValidation验证组件的使用情况。文章从构建间的验证器开始&#xff0c;到最后的结果&#xff0c;以及复杂验证等都做了比较深入的讲解和使用…

EhCache RMI 分布式缓存/缓存集群

EhCache 系统简介 EhCache 是一个纯 Java 的进程内缓存框架&#xff0c;具有快速、精干等特点。 EhCache 的主要特性有&#xff1a; 快速、精干简单&#xff1b;多种缓存策略&#xff1b;缓存数据有两级&#xff1a;内存和磁盘&#xff0c;因此无需担心容量问题&#xff1b;缓存…

谈谈博客园和写博客,以及通过博客遇到的那些人

不知不觉&#xff0c;博客园园龄已经5年11个月了&#xff0c;还曾依稀的记得&#xff0c;那是研究生毕业设计搞完了&#xff0c;有没有什么事情可以做&#xff0c;只能每天背个屌丝的书包去学院机房&#xff0c;狂赚CSDN积分&#xff0c;曾经高峰期的时候CSDN积分达到16000分&a…

SmartHome

ZigBee: CEL MeshConnect ZICM357SP2-1 Z-Wave: ZM4101AA-CME3

Python函数中的参数(二)

当使用混合特定的参数匹配模型时&#xff0c;Python将会遵循以下有关顺序的法则&#xff1a; 1、在函数调用中&#xff0c;参数必须以这样的顺序出现&#xff1a;任何位置参数&#xff08;Value&#xff09;、任何关键字参数&#xff08;name Value&#xff09;和*sequence形式…