Android实现发短信,打电话

两个android模拟器实现打电话发短信的模拟状态  具体步骤:首先,我们要启动两个android模拟器。只有这样,才能模拟效果。1.第一个模拟器,我们通过eclipse启动。具体方法是:打开你的eclipse,随便运行一个项目。Eclipse会帮你启动我们的第一个android模拟器。ID为5554.2.  第二个模拟器,我们通过DOS命令启动。具体方法:“开始”-“运行”-“CMD打开一个命令行窗口。然后cd 命令到你的android SDK目录的tools文件夹下面,输入“emulator -data foo”,回车。稍等片刻,系统即可帮你启动又一个新 阅读详情

最近做的这个HTML5项目中有2个调用本地的打电话,发短信功能,之后就去在网上找实现方式下面就是实现方式。

  1. 首先想到就是权限问题所以在AndroidManifest中添加权限
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.my.test">
    
        <!-- 允许程序发送SMS短信 -->
        <uses-permission android:name="android.permission.SEND_SMS"/>
        <!-- 允许程序读取短信息 -->
        <uses-permission android:name="android.permission.READ_SMS"/>
        <!-- 允许程序监控一个将收到短信息,记录或处理 -->
        <uses-permission android:name="android.permission.RECEIVE_SMS"/>
        <!-- 打电话 -->
        <uses-permission android:name="android.permission.CALL_PHONE"/>
    
        <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:supportsRtl="true"
            android:theme="@style/AppTheme">
            <activity android:name=".MainActivity">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
    
        </application>
    
    </manifest>
  2. 布局文件
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/activity_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        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="com.my.test.MainActivity">
    
        <Button
            android:id="@+id/btn_call1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="打电话(调到拨号页面)"
            android:textAllCaps="false" />
    
        <Button
            android:id="@+id/btn_call2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="打电话(直接拨号)"
            android:textAllCaps="false" />
    
        <Button
            android:id="@+id/btn_send_message1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="发短信(第一种方式)"
            android:textAllCaps="false" />
    
        <Button
            android:id="@+id/btn_send_message2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="发短信(第二种方式)"
            android:textAllCaps="false" />
    
        <Button
            android:id="@+id/btn_send_message3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="发短信(跳到发送短信页面)"
            android:textAllCaps="false" />
    
    </LinearLayout>
    
  3. Activity页面代码
    package com.my.test;
    
    import android.app.Activity;
    import android.app.PendingIntent;
    import android.content.BroadcastReceiver;
    import android.content.Context;
    import android.content.Intent;
    import android.content.IntentFilter;
    import android.net.Uri;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.telephony.PhoneNumberUtils;
    import android.telephony.SmsManager;
    import android.util.Log;
    import android.view.View;
    import android.widget.Button;
    import android.widget.Toast;
    
    import java.util.List;
    
    public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    
        private Button btn_call1;
        private Button btn_call2;
        private Button btn_send_message1;
        private Button btn_send_message2;
        private Button btn_send_message3;
        private final String TAG = getClass().getSimpleName();
        private SMSBroadcastReceiver1 smsBr1;
        private SMSBroadcastReceiver2 smsBr2;
        private IntentFilter intentFilter1;
        private IntentFilter intentFilter2;
        private final static String SENT_SMS_ACTION = "SENT_SMS_ACTION";
        private final static String DELIVERED_SMS_ACTION = "DELIVERED_SMS_ACTION";
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            btn_call1 = (Button) findViewById(R.id.btn_call1);
            btn_call2 = (Button) findViewById(R.id.btn_call2);
            btn_send_message1 = (Button) findViewById(R.id.btn_send_message1);
            btn_send_message2 = (Button) findViewById(R.id.btn_send_message2);
            btn_send_message3 = (Button) findViewById(R.id.btn_send_message3);
    
            btn_call1.setOnClickListener(this);
            btn_call2.setOnClickListener(this);
            btn_send_message1.setOnClickListener(this);
            btn_send_message2.setOnClickListener(this);
            btn_send_message3.setOnClickListener(this);
    
            //注册广播
            smsBr1 = new SMSBroadcastReceiver1();
            intentFilter1 = new IntentFilter(SENT_SMS_ACTION);
            registerReceiver(smsBr1, intentFilter1);
    
            smsBr2 = new SMSBroadcastReceiver2();
            intentFilter2 = new IntentFilter(DELIVERED_SMS_ACTION);
            registerReceiver(smsBr2, intentFilter2);
    
        }
    
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.btn_call1:
                    callPhone1("10086");
                    break;
    
                case R.id.btn_call2:
                    callPhone2("10086");
                    break;
    
                case R.id.btn_send_message1:
                    sendMessage1("10086", "119");   //10086查流量短信
                    break;
    
                case R.id.btn_send_message2:
                    sendMessage2("10086", "113");   //10086查话费短信
                    break;
    
                case R.id.btn_send_message3:
                    sendMessage3("15164054765", "测试");
                    break;
            }
        }
    
        @Override
        protected void onDestroy() {
            super.onDestroy();
            unregisterReceiver(smsBr1);
            unregisterReceiver(smsBr2);
        }
    
        /**
         * 打电话
         *
         * @param tel 电话号码
         */
        private void callPhone1(String tel) {
            Intent intent = new Intent(Intent.ACTION_DIAL);
            intent.setData(Uri.parse("tel:" + tel));
            startActivity(intent);
        }
    
        /**
         * 打电话
         *
         * @param tel 电话号码
         */
        private void callPhone2(String tel) {
            Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + tel));
            startActivity(intent);
        }
    
        /**
         * 发送短信
         *
         * @param tel     电话号码
         * @param content 短息内容
         */
        private void sendMessage1(String tel, String content) {
            Intent sendIntent = new Intent(SENT_SMS_ACTION);
            PendingIntent sendPI = PendingIntent.getBroadcast(this, 0, sendIntent, 0);
    
            SmsManager smsManager = SmsManager.getDefault();
            List<String> divideContents = smsManager.divideMessage(content);
            for (String text : divideContents) {
                smsManager.sendTextMessage(tel, null, text, sendPI, null);
            }
        }
    
        /**
         * 发送短信
         *
         * @param tel     电话号码
         * @param content 短息内容
         */
        private void sendMessage2(String tel, String content) {
            Intent deliverIntent = new Intent(DELIVERED_SMS_ACTION);
            PendingIntent deliverPI = PendingIntent.getBroadcast(this, 0, deliverIntent, 0);
    
            SmsManager smsManager = SmsManager.getDefault();
            List<String> divideContents = smsManager.divideMessage(content);
            for (String text : divideContents) {
                smsManager.sendTextMessage(tel, null, text, null, deliverPI);
            }
        }
    
        /**
         * 发送短信(掉起发短信页面)
         *
         * @param tel     电话号码
         * @param content 短息内容
         */
        private void sendMessage3(String tel, String content) {
            if (PhoneNumberUtils.isGlobalPhoneNumber(tel)) {
                Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:" + tel));
                intent.putExtra("sms_body", content);
                startActivity(intent);
            }
        }
    
        private class SMSBroadcastReceiver1 extends BroadcastReceiver {
    
            @Override
            public void onReceive(Context context, Intent intent) {
                switch (getResultCode()) {
                    case Activity.RESULT_OK:
                        Toast.makeText(context, "短信发送成功", Toast.LENGTH_SHORT).show();
                        break;
                    case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                        Log.e(TAG, "SmsManager.RESULT_ERROR_GENERIC_FAILURE");
                        break;
                    case SmsManager.RESULT_ERROR_RADIO_OFF:
                        Log.e(TAG, "SmsManager.RESULT_ERROR_RADIO_OFF");
                        break;
                    case SmsManager.RESULT_ERROR_NULL_PDU:
                        Log.e(TAG, "SmsManager.RESULT_ERROR_NULL_PDU");
                        break;
                }
            }
        }
    
        private class SMSBroadcastReceiver2 extends BroadcastReceiver {
    
            @Override
            public void onReceive(Context context, Intent intent) {
                Toast.makeText(context, "短信发送成功", Toast.LENGTH_SHORT).show();
            }
        }
    }


Android应用开发:电话与短信功能集成指南 Android提供了丰富的API,允许开发者在应用程序中实现电话拨打和短信发送功能。这些API不仅限于基本的通讯功能,还包括了状态监听和权限管理等高级特性,为开发者提供了灵活的操作空间和深度集成的可能性。在Android系统中,权限管理是保障用户隐私和设备安全的重要机制。每个应用都运行在自己的沙箱环境中,无法访问其他应用或系统资源,除非系统授予了相应的权限。对于电话和短信服务来说,由于涉及用户的通信隐私,Android系统要求应用在执行相关操作时必须获得明确的权限授权。 阅读详情

相关推荐

零基础学习大气污染模式(WRF、WRF-chem、smoke、camx等)

零基础学习大气污染模式(WRF、WRF-chem、smoke、camx等)

weixin_56135535的博客 653

Android实现打电话,发短信

长按“发短信”直接将短信发送出去。点击“发短信”进入编辑短信界面。点击“打电话”进入拨号界面。长按“打电话”直接拨打电话。

m0_65627943的博客 1359

ArcGIS遥感影像分类技术在植被覆盖度计算中的应用

本文详细介绍了如何利用ArcGIS遥感影像分类技术高效计算植被覆盖度。通过数据准备、监督与非监督分类方法详解,并结合制表分析与栅格计算器进行面积统计,最终实现从分类图到覆盖度百分比的全流程自动化与可视化,为生态评估与规划提供精准数据支持。

weixin_29091445的博客 419

Android Studio实现简单拨号,短信发送,照相机调用,地图打开的功能(Android Studio学习笔记3)

Android Studio实现简单拨号,短信发送,照相机调用,地图打开的功能一、实现简单拨号二、实现短信发送三、 一、实现简单拨号 拨号界面: 利用intent进行拨号,实现代码: 此时启动,拨号发生错误: 因为没有权限,不能拨号,因此需要先获得权限。 首先在配置文件中设置权限: <uses-permission android:name="android.permission.CALL_PHONE"/> 之后在类中加上版本号判断方法和权限判断方法: protect

Baker的博客 2425

ComfyUI破限版全中文AI绘画环境搭建与工作流实战指南

节点式工作流是AI绘画领域的核心技术架构,通过将图像生成过程拆分为可配置的模块化节点,实现了对Stable Diffusion模型的精细化控制。其技术原理基于数据流编程范式,每个节点负责特定功能处理,如文本编码、采样器配置和VAE解码等。这种设计在工程实践中的核心价值在于提供了可追溯、可复用的可视化工作流,特别适合需要参数调优和批量生产的商业场景。ComfyUI作为典型的节点式AI绘画工具,在破限版中针对中文用户优化了界面支持和显卡兼容性,显著降低了技术门槛。在实际应用中,结合ControlNet和LoRA

weixin_29038155的博客 446

vue 插件vue-awesome-swiper实现 三张图片,左右两边显示一半的效果的示例

希望我的愚见能够帮助你哦~,若有不足之处,还望指出,你们有更好的解决方法,欢迎大家在评论区下方留言支持,大家一起相互学习参考呀~

weixin_50450473的博客 3244

Android发送短信最简单代码实现

Android发送短信最简单代码实现,发送短信原理,接收不到短信原因汇总,smsmanager的使用,广播查看短信发送状态

weixin_58814750的博客 4881

嘉立创EDA报错:元件引脚与焊盘未对应报错解决记录

原件引脚与焊盘未对应报错解决方法,一文总结!

2303_77013775的博客 1万+

android实现打电话 发短信功能

之前看了李兴华的视频,他在android手机中实现发短信 打电话功能有点麻烦,最近做毕设需要用这个功能,在网上找了一些比较简单方法,调用系统就可以 1  打电话  在Manifest中添加权限   后再Activity中添加代码 case R.id.call_user: if (usertel.length() > 0) { Intent intent =

yongchunaq的专栏 1194

openssl命令数据摘要详解(SM3、sha256、MD5、dss1、mdc2、ripemd160)

SM3是由中国密码学家设计的密码哈希函数,是中国国家密码管理局(National Cryptographic Authority,简称:CNCA)颁布的国家密码算法标准。SM3属于密码杂凑函数家族,它可以计算任意长度的消息并生成固定长度(256比特,即32字节)的哈希值。SM3生成的哈希值长度为256比特(32字节),不管输入消息的长度如何,输出始终是固定的。SM3将输入数据划分为512比特(64字节)的分组,并对每个分组进行处理。

N阶二进制的博客 4460

18、Excel VBA编程:自定义函数创建与代码调试全攻略

本文详细介绍了Excel VBA中自定义函数的创建方法,以获取单元格注释为例演示了完整开发流程,并深入讲解了代码调试的重要性与核心工具。内容涵盖三种主要错误类型及其应对策略,系统介绍了调试工具栏、断点、逐行执行、Locals窗口、Immediate窗口等实用功能。通过综合案例展示了如何运用调试技术解决实际问题,并总结了提前规划、逐步测试、日志记录等最佳实践,帮助读者提升VBA编程效率与代码质量。

life6的博客 100

【Android】打电话与发短信的实现

1.首先在AndroidManifest中加入:   uses-permission android:name= "android.permission.CALL_PHONE" />    uses-permission android:name="android.permission.SEND_SMS" />

u014291735的专栏 605

ExpressLRS(ELRS)接收机技术全景:从历史演进、技术底层到产业生态全解析——上

ExpressLRS(ELRS)是一种由全球开源社区驱动的双向射频遥控链路协议栈,其接收机作为核心终端,承担信号接收解调、遥控指令解析、飞控数据交互与遥测回传等关键功能。自2018年问世以来,ELRS凭借极致性能、低成本、开放生态和强兼容性,从航模DIY方案发展为消费级无人机领域的事实标准,并逐步渗透工业级场景。 ELRS接收机采用模块化分层架构,支持2.4GHz和900MHz双频段,通过LoRa、FLRC、FSK多调制模式实现低延迟与远距离平衡。其核心技术包括自适应跳频抗干扰、TDD双向链路和极简数据包。

bother3000的博客 302

android打电话、发短信实现

打电话: Intent intent = newIntent(Intent.ACTION_CALL,Uri.parse("tel:"+"156666666666"));  this.startActivity(intent);   加上打电话的权限:发短信:                 //发短信        String content ="11

com360的专栏 2万+

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

Android studio 实现打电话发短信浏览网页功能 android开发小实验

Android开发小实验 Android studio 实现打电话发短信浏览网页功能

hjjshua的博客 5605

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

手把手教你如何在安卓平台上实现打电话发短信的功能

首发地址 http://www.eoeandroid.com/thread-228079-1-1.html 1 案例目的 本案例通过一个简单通讯工具来巩固android的activity、LinearLayout布局、基本控件Button、打电话发短信以及应用程序交互通信Intent的使用。本案例重点讲解android中事件处理原理以及该原理在项目中的应用。 2 案例介绍 零距通这个通...

weixin_30276935的博客 199

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

android实现打电话和发短信的功能(10学员张晓丛)

----------实现打电话的功能 新建一个android项目APhone 因为应用要使用手机的电话服务,所以要在清单文件AndroidManifest.xml中添加电话服务权限 http://schemas.android.com/apk/res/android"     package="cn.csdn.Android"     android:versionCode="1"

redarmychen的专栏 7774

Android信使intent学习源码,实现打电话,发短信

【本demo知识要点】 请查看《Android组件之间的信使intent学习源码,启动activity并传值》 通过本demo可以学习到: 启动打电话程序。 启动发短信程序。 【实现步骤】 实例化intent类; 设置intent的actio

cndemoz的专栏 681

android实现打电话发短信

布局文件 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <LinearLayout android:layout_width="matc

huangbaokang的博客 435

Android 实现直接打电话与直接发短信

记录安卓实现直接打电话以及直接发短信以及相应的权限申请 相应的Action (1)String action = Intent.ACTION_DIAL;实现跳转到拨号界面 (2)Intent intent = new Intent(Intent.ACTION_SENDTO);跳转到信息界面 (3)String action = Intent.ACTION_CALL;直接拨打电话(需要权限) <!--打电话的权限--> <uses-permission android:nam.

weixin_44141172的博客 2030

Android实现打电话和发短信

Android项目经常要实现的调用系统拨号盘打电话,以及调用系统短信发送器发送短信

sinat_28021815的博客 633

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

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

weixin_42508903的博客 374

Android 实现打电话和发短信

package com.zlz; import java.util.List; import android.app.Activity; import android.app.PendingIntent; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android

673

两个android模拟器 实现 打电话 发短信

 具体步骤:第一,启动两个android模拟器。        1.第一个模拟器,通过eclipse启动。        具体方法是:打开eclipse,任意运行一个android项目。Eclipse会启动一个android模拟器。ID通常为5554.        2.  第二个模拟器,通过DOS命令启动。        具体方法:“开始”-“运行”-“CMD打开一个命令

Working harder, getting stronger! 2763
上一篇: 使用Chrome调试web app
下一篇: SpringMVC中遇到Failed to read candidate component class: file XXX
bbccloud
博客等级 码龄11年 23粉丝 25原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值