一、拨打电话

1、首先做好界面,代码如下:

layout =>activity_main.xml 中

<LinearLayout 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:orientation="vertical"
tools:context=".MainActivity" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/head_lable" /> <EditText
android:id="@+id/txt_number"
android:layout_width="match_parent"
android:layout_height="wrap_content" /> <Button
android:id="@+id/btn_dialer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="拨号"
android:layout_gravity="right"
/> </LinearLayout>

效果图如下 :

2、下面就点击拨号事件进行操作:

1)点击拨号按钮=》获取拨号的id==>监听拨号事件setOnClickListener的一个新方法。

2)实现这个方法

2.1)获取编辑框的id==>然后获取其值。

2.2)获取值以后就是要实现打电话的意图啊new一个意图。

意图的动作是打电话、获取电话号码。

2.3)把这个意图告诉系统(startActivity(intent);)

3)加入打电话的权限(在AndroidManifest.xml中)。<uses-permission android:name="android.permission.CALL_PHONE"/>

src=>cn.rfvip.dialer0204=>MainActivity.java 中

package cn.rfvip.dialer0204;

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText; public class MainActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//给按钮一个监听事件
Button bt=(Button) findViewById(R.id.btn_dialer);
bt.setOnClickListener(new MyLisen()); //1、首先获取按钮的id==>然后监听 事件==》获取文本的id==>然后获取其值==》意图是打电话(new一个)==》打电话动作、电话号码(加Tel)。
//把意图告诉系统;
//打电话的权限加入 } class MyLisen implements OnClickListener{ @Override
public void onClick(View v) {
// TODO 自动生成的方法存根 EditText eT=(EditText) findViewById(R.id.txt_number);
String phone=eT.getText().toString(); Intent intent=new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:"+phone));
startActivity(intent);
}} }

二、发送短信

在activity_main.xml

<LinearLayout 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:orientation="vertical"
tools:context=".MainActivity" > <EditText
android:id="@+id/ed_sms_phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="phone"
android:hint="短信号码"
/>
<EditText
android:id="@+id/ed_sms_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="短信内容"
android:gravity="top"
android:lines="5"
/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="sengsms"
android:onClick="sendsms"
/> </LinearLayout>

在MainActivity.java

package cn.rfvip.sendsms;

import android.os.Bundle;
import android.app.Activity;
import android.telephony.SmsManager;
import android.view.Menu;
import android.view.View;
import android.widget.EditText; public class MainActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void sendsms(View v) {
EditText ed_sms_phone=(EditText) findViewById(R.id.ed_sms_phone);
EditText ed_sms_content=(EditText) findViewById(R.id.ed_sms_content);
String sms_phone = ed_sms_phone.getText().toString();
String sms_content = ed_sms_content.getText().toString(); SmsManager sm=SmsManager.getDefault();//获取短信管理器

ArrayList<String> smss= sm.divideMessage(sms_content);//分割短信
    for(String string:smss)
   {
   sm.sendTextMessage(sms_phone, null, string, null, null);

}


}

}

记得加入发送短信权限哦    <uses-permission android:name="android.permission.SEND_SMS"/>

android 入门 002 (拨打电话,发送短信)的更多相关文章

  1. Android-读取操作系统通话记录并/拨打电话/发送短信/复制号码到拨号盘

    apps目录的contacts应用(有读取通话记录功能),是访问provider目录的provider.contacts应用(有暴露通话记录),所以要阅读Android操作系统源码-->pack ...

  2. iOS_拨打电话/发送短信

    GitHub address : https://github.com/mancongiOS/makeACallAndSendMessage.git 功能一: 拨打电话 1.可以有提示框.提示该电话号 ...

  3. 调用 url_launcher 模块打开外部浏 览器 打开外部应用 拨打电话 发送短信

    1.Flutter url_launcher 模块    Flutter url_launcher 模块可以让我们实现打开外部浏览器.打开外部应用.发送短信.拨打电话等功能.    https://p ...

  4. Arduino+sim800C家居安防火灾报警 拨打电话 发送短信例程程序

    家居安防报警器,参考程序. 火灾报警 涉及用sim800c发短信,拨打电话通知. 接线: Sim800c 3.3V -> Arduino 3.3V Sim800c GND -> Ardui ...

  5. IOS中调用系统拨打电话发送短信

    一.调用打电话界面 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat ...

  6. android使用Intent操作拨打号码发送短信

    Activity程序Activity.java package com.example.intentcaseproject; import android.net.Uri; import androi ...

  7. html5 安卓拨打电话 发短信

    方法一: <input name=”phone_no” format=”*m” value=”13″/> <do type=”option” label=”呼出号”> < ...

  8. android中调用系统的发送短信、发送邮件、打电话功能

    1 调用发送短信功能: Uri smsToUri = Uri.parse("smsto:");  Intent sendIntent = new Intent(Intent.ACT ...

  9. Android面试收集录 电话、短信和联系人、多媒体技术

    1.请写出调用系统拨号界面? Intent intent=new Intent(Intent.ACTION_DIAL,Uri.pase("tel:12345678910")); s ...

随机推荐

  1. 一群猴子排成一圈,按1,2,...,n依次编号。然后从第1只开始数,数到第m只,把它踢出圈,从它后面再开始数,再数到第m只,在把它踢出去...,如此不停的进行下去,直到最后只剩下一只猴子为止,那只猴子就叫做大王。要求编程模拟此过程,输入m、n, 输出最后那个大王的编号

    <?php/** * [猴子选大王] * @param  [type] $m [猴子数] * @param  [type] $n [出局次数] * @return [type]    [desc ...

  2. ligerui_ligerTree_001_第一个“树”效果

    折叠.展开.有复选框.没有复选框: 源码地址:http://download.csdn.net/detail/poiuy1991719/8571255 效果图: <%@ page languag ...

  3. Demo12SimpleAdapter

    /Users/alamps/AndroidStudioProjects/Demo12SimpleAdapter/Demo12SimpleAdapter/src/main/res/layout/data ...

  4. paper 55:图像分割代码汇总

    matlab 图像分割算法源码 1.图像反转 MATLAB程序实现如下:I=imread('xian.bmp');J=double(I);J=-J+(256-1); %图像反转线性变换H=uint8( ...

  5. 经典SQL

    一.基础 1.说明:创建数据库CREATE DATABASE database-name 2.说明:删除数据库drop database dbname3.说明:备份sql server--- 创建 备 ...

  6. python 三元运算符

    print (1==2) and 12 or 4 b=12 if 1==2 else 4print(b)

  7. 网卡ifcfg-eth0配置

    ifcfg-ethx网卡配置 文件路径 [root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0     ...

  8. Servlet乱码

      request.setCharacterEncoding():是设置从request中取得的值或从数据库中取出的值 (只管post方式提交的问题///get需在server.xml中的: < ...

  9. html5 canvas 笔记一(基本用法与绘制图形)

    <canvas> 元素 <canvas id="tutorial" width="150" height="150"> ...

  10. Shipyard远程API

    1.鉴权模块 1.1 Login,获取token POST  http://192.168.31.149:8080/auth/login Headers Content-Type: applicati ...