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 ...
随机推荐
- babel使用中不想使用 严格模式 如何去除?
使用babel进行es6转es5时,默认转化之后是严格模式,有些时候我们想去除严格模式. 解决方法如下 安装 babel-plugin-transform-remove-strict-mode 依赖 ...
- jenkins备份与恢复
jenkins这里我通过thinbackup插件进行对jenkins的配置备份与恢复 1丶安装thinbackup插件 2丶系统管理选择thinbackup插件 3丶创建备份目录 mkdir /bac ...
- 8-16 不无聊序列 non-boring sequences uva1608
题意: 如果一个序列的任意连续子序列中至少有一个只出现一次的元素 则称这个序列是 不无聊序列 输入一个n个元素的序列a 判断是不是不无聊序列 一开始想当然 以为只要 2位的子序列都满足即可 ...
- ECshop语言包lang的加载原理
当前使用的ecshop的版本:2.7.3,ecshop 2.7.3版本的网店系统的语言包的位置是ecshop文件下 languages/xxx/ 其中的xxx表示各种语言的文件夹,里面存放指定语言 ...
- 华三IRF的配置
https://blog.csdn.net/VictoryKingLIU/article/details/79255901 拓扑结构 1 配置成员编号(重启) 2 配置成员优先级(大的主设备) 3 配 ...
- R语言实战(十)处理缺失数据的高级方法
本文对应<R语言实战>第15章:处理缺失数据的高级方法 本文仅在书的基础上进行简单阐述,更加详细的缺失数据问题研究将会单独写一篇文章. 处理缺失值的一般步骤: 识别缺失数据: 检查导致数据 ...
- linux安装及配置c++的opencv库
linux安装及配置c++的opencv库 前言: 最近想搞个机器视觉的比赛,要求是linux+opencv环境,没有做过opencv开发的我配置环境就配了两天,看来很多乱七八糟的博客,终于装好了.网 ...
- 「长乐集训 2017 Day10」划分序列 (二分 dp)
「长乐集训 2017 Day10」划分序列 题目描述 给定一个长度为 n nn 的序列 Ai A_iAi,现在要求把这个序列分成恰好 K KK 段,(每一段是一个连续子序列,且每个元素恰好属于一 ...
- 【基础知识】ASP.NET[基础二(aspx)]
1.cs可以调用aspx中的runat=server控件,aspx中也可以访问测试中定义的字段.函数,还可以编写复杂的C#代码,for等所有C#代码都可以写在aspx中(不推荐这样写): 2.把代码写 ...
- 1008 Elevator (20)(20 point(s))
problem The highest building in our city has only one elevator. A request list is made up with N pos ...