1.创建项目,新建Activity
2.sendSmsActivity.java

package com.otis.ui;import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;import android.Manifest;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;import com.otis.slamrobot.R;public class SendSmsActivity extends AppCompatActivity {EditText phone, content;Button send;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_send_sms);ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.SEND_SMS} , -1);// 获取SMSManager管理器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() {@Overridepublic void onClick(View v) {String phoneNum = phone.getText().toString();String contentText = content.getText().toString();//创建一个android.app.PendingIntent对象PendingIntent pi = PendingIntent.getActivity(SendSmsActivity.this, 0, new Intent(), 0);//发送短信smsManager.sendTextMessage(phoneNum, null, contentText, pi, null);//提示短信发送完成Toast.makeText(SendSmsActivity.this, "短信发送完成", Toast.LENGTH_SHORT).show();System.out.println(phoneNum+contentText);}});}}

3.AndroidMainfest.xml:

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

4.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.ui.SendSmsActivity"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="收件人"/><EditTextandroid:id="@+id/et_phone"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginLeft="10dp"/></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="10dp"android:orientation="horizontal"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="发送内容"/><EditTextandroid: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><Buttonandroid:layout_gravity="center_horizontal"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="发送"android:id="@+id/btn_send"/>
</LinearLayout>

5.关于权限问题:
需要在手机上设置打开:设置–>权限管理–>应用–>找到对应的APP–>信任此应用

android 实现发送短信功能以及解决权限问题相关推荐

  1. linux 短信功能,Android调用系统短信功能发送短信

    Android调用系统短信功能发送短信有两种方法: 第一种,设定发送的号码,和内容,界面没有联系人,群组组等按钮,如下图所示: 代码如下: Uri smsToUri = Uri.parse(" ...

  2. android 发短信意图,android代码实现打电话和发送短信功能

    android代码实现打电话和发送短信功能 发布时间:2020-05-27 11:57:17 来源:亿速云 阅读:172 作者:鸽子 1.XML布局 xmlns:app="http://sc ...

  3. 【短信发送】实现腾讯云发送短信功能--工具类和SpringBoot配置两种方法实现

    实现腾讯云发送短信功能--工具类和SpringBoot配置两种方法实现 一.开通腾讯云短信服务 二.工具类--使用qcloudsms实现短信发送 三.Spring Boot项目引入短信发送功能 我们发 ...

  4. TP5调用阿里云短信接口实现发送短信功能

    TP5调用阿里云短信接口实现发送短信功能 工作需要,对接阿里云的短信服务,借此记录一下(网站 www.lelee.top) 主要分为两个部分,一是下载官方的Demo事例,这个不需要多说,自己去下载就行 ...

  5. 实现 Java 发送短信功能

    前言 前几日,有粉丝后台私信我如何实现发送短信的功能,刚好久一刚刚用到了这个功能,就把具体的实现过程记录下来,分享给大家. 我们日常使用的软件或者网站,大部分都在使用短信业务,比如注册.验证码功能.还 ...

  6. springboot集成阿里云短信服务,实现发送短信功能

    springboot集成阿里云短信服务,实现发送短信功能 准备工作: 1.登陆阿里云->进入控制台->开通短信服务(进入后根据提示开通) 2.充值(借人家平台发短信你以为不要钱的?我充了3 ...

  7. php可以发短信的代码,PHP代码函数实现PHP发送短信功能

    //PHP代码函数实现PHP发送短信功能 //本代码基于开心洋葱 运行 //代码来源:开心洋葱 //PHP发送短信开心洋葱专用(PHP代码函数) //本代码基于开心洋葱 运行 //代码来源:开心洋葱 ...

  8. 7 分钟实现 Java 发送短信功能!

    阅读文本大概需要 7 分钟. 前言 前几日,有粉丝后台私信我如何实现发送短信的功能,刚好久一刚刚用到了这个功能,就把具体的实现过程记录下来,分享给大家. 我们日常使用的软件或者网站,大部分都在使用短信 ...

  9. android实现发送短信的功能

    在上次的博客中已经实现了拨打电话的功能,但是在实际中使用短信的几率也是比较大的,好多手机卡短信都是包月的,像移动校园卡每个月可以发200条短信,超出之后才付钱.但这些日子已经一去不复返了,我也毕业了, ...

最新文章

  1. processing link链接
  2. SQL Server2005完全卸载
  3. DDD领域驱动设计特点及难点
  4. 异常:Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
  5. CompletableFuture详解~thenApplyAsync
  6. 回文子序列_计算回文子序列的总数
  7. python mysql ssl,python – 在SQLAlchemy中使用SSL
  8. numpy.cov() 计算协方差矩阵
  9. 01-eclipse打包运行程序总是报错java.lang.NoClassDefFoundError和ava.lang.ClassNotFoundException(打包原理)
  10. 单元测试 - mock异常
  11. 如何用MathType快速输入公式
  12. (二)OpenCV Mat常用属性和方法
  13. J2EE的13个规范之(三) Servlet简单介绍
  14. 我的第一个Python程序:Luogu1001 A+B Problem
  15. 微信撤回软件安卓版_微信强制撤回软件下载-微信强制撤回消息工具(不限时间) v1.0安卓版_5577安卓网...
  16. 读写SharedPreferences中的数据
  17. 博弈论中SG函数的解释与运用
  18. 用python读取Excel数据
  19. 如何将华为云服务器重做系统并保留其中的指定数据
  20. ubuntu14.04上安装Mist

热门文章

  1. 阿里的绩效考核:赏明星,杀白兔,野狗要示众
  2. 年度全球区块链最有影响力人物排行榜TOP10
  3. 1521端口 mysql_Linux开放1521端口允许网络连接Oracle Listener
  4. Ue4----渲染流程
  5. LVS介绍与相应部署
  6. Python中的数学运算操作符使用进阶
  7. 【技术探索】专注连接的LinkFabric技术详解!
  8. 第一章 linux操作系统
  9. 从零开始在Windows上构建Android版的Tensorflow Lite
  10. 移动网流量用户身份识别系统的源代码_智能车牌识别系统全自动化的功能