Android 调用发送短信的方法
作者:1140566087 发布时间:2023-05-30 22:56:40
标签:Android,调用,短信
Android 调用发送短信的方法
功能:调用发送短信功能
1 、 权限
<uses-permission android:name="android.permission.SEND_SMS"/>
2、具体实现
Uri smstoUri = Uri.parse("smsto:");
Intent intent = new Intent(Intent.ACTION_VIEW,smstoUri);
intent.putExtra("address","电话号码"); // 没有电话号码的话为默认的,即显示的时候是为空的
intent.putExtra("sms_body","短信内容"); // 设置发送的内容
intent.setType("vnd.android-dir/mms-sms");
startActivity(intent);
Activity 代码:
public class MainActivity extends Activity {
private EditText phone ,message;
private Button sendbtn;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
phone = (EditText) findViewById(R.id.phone);
message = (EditText) findViewById(R.id.message);
sendbtn = (Button) findViewById(R.id.sendbtn);
//点击发送短信
sendbtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String p = phone.getText().toString();
String m = message.getText().toString();
Uri smstoUri = Uri.parse("smsto:"); // 解析地址
Intent intent = new Intent(Intent.ACTION_VIEW,smstoUri);
intent.putExtra("address",p); // 没有电话号码的话为默认的,即显示的时候是为空的
intent.putExtra("sms_body",m); // 设置发送的内容
intent.setType("vnd.android-dir/mms-sms");
startActivity(intent);
}
});
}
}
Mainfest.xml 配置文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.message"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="10" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.message.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<!-- 发送短信权限 -->
<uses-permission android:name="android.permission.SEND_SMS" />
</manifest>
布局示意图:
<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<EditText
android:id="@+id/phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:ems="10"
android:inputType="number" >
<requestFocus />
</EditText>
<Button
android:id="@+id/sendbtn"
style="?android:attr/buttonStyleSmall"
android:layout_width="150dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="28dp"
android:text="Send" />
<EditText
android:id="@+id/message"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/sendbtn"
android:layout_alignLeft="@+id/phone"
android:layout_marginBottom="48dp"
android:ems="10" />
</RelativeLayout>
来源:http://sunzone.iteye.com/blog/1998110
0
投稿
猜你喜欢
- 学习要求:知道一点儿函数式接口和Lambda表达式的基础知识,有利于更好的学习。1.先体验一下Stream的好处需求:给你一个ArrayLi
- 我使用的版本是SpringBoot 2.6.4可以实现注入不同的库连接或是动态切换库<parent>
- 线程可以有六种状态:1.New(新创建)2.Runnable(可运行)(运行)3.Blocked(被阻塞)4.Waiting(等待)5.Ti
- Springmvc调用存储过程,并返回存储过程返还的数据java后端很多时候都需要和数据库进行交互,并返回业务数据。一般情况下都会采用执行S
- 实际应用中,我们会有在项目服务启动的时候就去加载一些数据或做一些事情这样的需求。 为了解决这样的问题,spring Boot 为我们提供了一
- 概要笔者近期做到对天气预报JSON数据解析,在此小记。天气预报接口:http://wthrcdn.etouch.cn/weather_min
- 今天讲一下目前移动领域很常用的技术——二维码。现在大街小巷、各大网站都有二维码的踪迹,不管是IOS、Android、WP都有相关支持的软件。
- 我们日常的工作中都使用开发工具(IntelliJ IDEA 或 Eclipse 等)可以很方便的调试程序,或者是通过打包工具把项目打包成 j
- 修改FeginCilent定义的服务名到指定服务通过覆盖类来修改对应的服务名,这里将所有的FeginClient对应的服务名都修改好。pac
- 解决Long型数据转换成json格式时丢失精度最近项目中突然发现雪花算法生成的数据库主键id返回给前端时和本身的值不一致,于是后端进行断点调
- 错误内容:com.alibaba.druid.pool.GetConnectionTimeoutException: wait millis
- 有看过我之前发表过的C#相关文章分享和阅读过我代码的朋友们可能会在我的代码里面经常看到各种各样的λ表达式动态拼接,C#
- 实践过程效果代码public partial class frmSplit : Form{ public frmS
- package com.chase.test;import java.util.ArrayList;import java.util.Has
- 最开始接触到相关的内容应该是从volatile关键字开始的吧,知道它可以保证变量的可见性,而且利用它可以实现读与写的原子操作。。。但是要实现
- springboot集成swagger3swagger3的springboot启动器jar包<!-- https://mvnrepos
- 前言提起子类、基类和方法继承这些概念,肯定大家都非常熟悉。毕竟,作为一门支持OOP的语言,掌握子类、基类是学习C#的基础。不过,这些概念虽然
- 茫茫人海千千万万,感谢这一秒你看到这里。希望我的能对你的有所帮助!共勉!愿你在未来的日子,保持热爱,奔赴山海!Java基础知识(多态)多态因
- Wrapper条件构造器updateForSet更新官方文档:https://baomidou.gitee.io/mybatis-plus-
- 很多App都有这种效果,特别一些电商类的App,顶部每隔几秒钟会向右翻页显示下张图片,用来作推广或者内容展示用的。今天来简单地模仿一下,还自