Android中怎样调用拨打电话?
Android系统原本就为手机设计,所以,在android系统中的不论什么App中,仅仅要愿意,拨打指定电话很方便。
核心就是使用Intent跳转,指定请求Action为Intent.ACTION_CALL 就可以。
【源代码下载】 http://www.code4apk.com/android-code/178
核心代码例如以下:
1 |
Intentnew Intent(Intent.ACTION_CALL,Uri.parse("tel:13888888888"); |
以下一起来实现这个功能:
第1步:新建一个activity :DialerAndMsgActivity
package com.android.dev; import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText; public class DialerAndMsgActivity extends Activity {
private Button dialerButton;
private EditText editTextPhoneNum; /** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main); dialerButton = (Button) findViewById(R.id.Button_Dialer);
editTextPhoneNum = (EditText) findViewById(R.id.EditText_PhoneNum); dialerButton.setOnClickListener(new View.OnClickListener(){ public void onClick(View arg0) {
Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+
editTextPhoneNum.getText()));
DialerAndMsgActivity.this.startActivity(intent);
} });
}
}
第2步:改动配置文件:main.xml
<? xml version="1.0" encoding="utf-8"? >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:id="@+id/TextView_Phone"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="@string/tell_tile" /> <EditText android:id="@+id/EditText_PhoneNum"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Button android:id="@+id/Button_Dialer"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="@string/button_call"/>
</LinearLayout>
第3步:在配置文件AndroidManifest.xml中加入拨号支持
1 |
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission> |
第4步调试执行:
android拨打电话
android拨打电话
Android中怎样调用拨打电话?的更多相关文章
- 【Android】Android开发初学者实现拨打电话的功能,拨打电话app小demo实现
作者:程序员小冰,GitHub主页:https://github.com/QQ986945193 新浪微博:http://weibo.com/mcxiaobing 首先先给大家看一下最终实现的效果: ...
- Android点击按钮拨打电话
代码改变世界 Android点击按钮拨打电话 public void callPhone(String str) { Intent intent=new Intent(); intent.setAct ...
- Android开发手记(15) 拨打电话和收发短信
1.Intent简介 Android组价之间的通信,由Intent来协助完成.Intent负责对应用中一次操作的动作.动作涉及数据.附加数据进行描述,Android则根据此Intent的描述,负责找到 ...
- Android无需申请权限拨打电话
Android打电话有两种实现方法: 第一种方法,拨打电话跳转到拨号界面.源代码如下: Intent intent = new Intent(Intent.ACTION_DIAL); Uri data ...
- android 入门 002 (拨打电话,发送短信)
一.拨打电话 1.首先做好界面,代码如下: layout =>activity_main.xml 中 <LinearLayout xmlns:android="http://sc ...
- Android学习笔记_1_拨打电话
1.首先需要在AndroidManifest.xml文件中加入拨打电话的权限,对应的配置文件: <?xml version="1.0" encoding="utf- ...
- android 中webview调用js
1.android中利用webview调用网页上的js代码. Android 中可以通过webview来实现和js的交互,在程序中调用js代码,只需要将webview控件的支持js的属性设置为true ...
- Android使用Intent实现拨打电话的动作
使用Intent实现打电话的动作,我们须要在 AnroidMainfest.xml中增加通话权限,打开这个文件,在application节点的前面增加以下内容 <uses-permission ...
- Android跳转到拨打电话的页面
在Android6.0之后,拨打电话需要用户授予动态权限,项目中有此需求,有一种简单的方法,直接携带电话号码跳转到系统拨打电话的页面,很多应用也是这么做的,这样可以减轻工作量 代码如下: Androi ...
随机推荐
- JSP的学习二(请求转发与 重定向)
一: 1.介绍知识点 1). 本质区别: 请求的转发只发出了一次请求, 而重定向则发出了两次请求. 具体: ①. 请求的转发: 地址栏是初次发出请求的地址. 请求的重定向: 地址栏不再是初次发出的请 ...
- matplotlib使用总结
一.简介 Matplotlib 是一个 Python 的 2D绘图库,它以各种硬拷贝格式和跨平台的交互式环境生成出版质量级别的图形.通过 Matplotlib,开发者可以仅需要几行代码,便可以生成绘图 ...
- 20172304 实验二 《Java面向对象程序设计》 实验报告
20172304 实验二 <Java面向对象程序设计> 实验报告 课程名称:<程序设计与数据结构> 学生班级:1723班 学生姓名:段志轩 学生学号:20172304 实验时间 ...
- 深度学习基础系列(五)| 深入理解交叉熵函数及其在tensorflow和keras中的实现
在统计学中,损失函数是一种衡量损失和错误(这种损失与“错误地”估计有关,如费用或者设备的损失)程度的函数.假设某样本的实际输出为a,而预计的输出为y,则y与a之间存在偏差,深度学习的目的即是通过不断地 ...
- Python 递归删除非空目录(包括子目录以及文件)
Python的OS模块自带rmdir和removedirs函数用于删除目录,但是两者都不能删除非空目录,以下代码定义了一个函数 remove_dir 用于删除非空目录. #作者官网 http://ww ...
- insert ignore duplicate key
Insert into T1select * from T2 where NOT EXISTS (select 1 from T1 X where X.GUID=T2.GUID);
- Here is a 10-line template that can solve most 'substring' problems子字符串问题的模板
转载自leetcode评论区:https://discuss.leetcode.com/topic/30941/here-is-a-10-line-template-that-can-solve-mo ...
- [ 原创 ]linux centos下配置java环境教程
一.环境 centos 7.2 二.目标 在CentOS7.2上安装jdk1.8(tar.gz安装包),并配置环境变量 jdk安装在/home/soft/jdk1.8.0-131目录下 具体步骤 1. ...
- CXF发布webservice
http://wenku.baidu.com/link?url=dTJpXcL0TXslGAYYC6SSOrPGvjyEb974ZGx9-0dymU32YDjxuP8DwlI1sFpPCGqu_ywW ...
- play framework系列之打包war
概览 Play framwork 是我们一直在使用的框架,从刚开始的简单使用,乱起八糟的jar包引用,项目组成员之间的下载项目之后的引用问题等,遇到各种问题,我都一一解决,我将在这个系列中奉上解决方案 ...