一、拨打电话

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. shell学习笔记(1)-变量

    1.shell中的变量可以自定义,shell中使用变量时用$ name="shero"echo "hi ${name}" root@shero-virtual- ...

  2. 卸载了mysql之后,mysql服务仍在,显示读取描述失败,错误代码2

    卸载了mysql之后,mysql服务仍在,显示读取描述失败,错误代码2 用360软件管家,卸载mysql5.5,卸载了mysql之后,再依次删除 mysql的安装目录.c盘下的隐藏文件夹Program ...

  3. 通过反射封装JDBC

    具体上代码我的BaseDao: public class BaseDao<T> {  private Class clazz;  private Properties pro=null;  ...

  4. 侧菜单栏的实现SlidingPaneLayout

    SlidingPaneLayout分为两部分,上面的 左划出部分和没划出的时候 <?xml version="1.0" encoding="utf-8"? ...

  5. js this 闭包

    var myObject = { value :, increment:function (inc){ ; } }; myObject .increment(); console.log(myObje ...

  6. 如何学习c++

    在之后的随笔中,我作为一个c++的初学者将会把我如何学习c++的经历尽可能详细的记录下来. 这里引用了JerryZhang在他的博文里面写的一段话,当作我的座右铭. 1.多交流:不管你的技术多么硬,你 ...

  7. 类名.class, class.forName(), getClass()区别

    1:Class cl=A.class; JVM将使用类A的类装载器, 将类A装入内存(前提是:类A还没有装入内存),不对类A做类的初始化工作.返回类A的Class的对象. 2:Class cl=对象引 ...

  8. webpack我遇到的一些坑

    我的第一个用于实验webpack的项目是一个拥有多个版本的项目.什么叫多个版本?这个项目对3个语言版本+3个不同城市版本+(移动端  + PC端),也就是3*3*2,18个版本. 我的第一次想法肯定是 ...

  9. SVN使用(一)

    SVN简介: 为什么要使用SVN? 程序员在编写程序的过程中,每个程序员都会生成很多不同的版本,这就需要程序员有效的管理代码,在需要的时候可以迅速,准确取出相应的版本. Subversion是什么? ...

  10. 鸟哥的linux私房菜学习记录之认识与分析登录档

    logwatch分析登录档