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 ...
随机推荐
- 湖南联通发福利了C#为你月赚150M流量回家过年不再愁
回家过年没流量怎么能行,这里教大家一个月赚150流量的方法,哈哈,首先下载联通客户端,本人只有android手机一台,没办法只能用 android的了,里面有一个悦分享,上几张图,图有有我赚的流量. ...
- CROC 2016 - Elimination Round (Rated Unofficial Edition) F - Cowslip Collections 数论 + 容斥
F - Cowslip Collections http://codeforces.com/blog/entry/43868 这个题解讲的很好... #include<bits/stdc++.h ...
- redhat重置密码
当忘记虚拟机密码时怎么办? 1.启动虚拟机,当虚拟机显示输入enter启动时输入e 2.再次用上下键选中你平时启动linux的那一项(类似于kernel /boot/vmlinuz-2.4.18-14 ...
- Java使用AES加密解密
AES加密机制: 密码学中的高级加密标准(Advanced Encryption Standard,AES),又称Rijndael加密法,是美国联邦政府采用的一种区块加密标准. 这个标准用来替代原先的 ...
- The Pragmatic Programmer 读书笔记
--在所有的弱点中,最大的弱点就是害怕暴露弱点. --责任是你主动担负的东西.你承诺确保某件事情正确完成,但你不一定能直接控制事情的每一个方面.除了尽你所能以外,你必须分析风险是否超出了你的控制.对于 ...
- XShell通过中转服务器直接连接目标服务器
最近由于公司生产环境的变化,使得我们不能使用自己的机器连接到生产环境去,而是要通过跳板机中转才可以连接.于是今天尝试使用 XShell 通过跳板机直接转接到生产环境. 一.使用代理方式 首先填写连接信 ...
- shellcode在栈溢出中的利用与优化
0x00 前言 在<Windows Shellcode学习笔记——shellcode的提取与测试>中介绍了如何对shellcode作初步优化,动态获取Windows API地址并调用,并通 ...
- Python168的学习笔记8
#coding:utf8 #斐波那契数列,第三项起,每一项都等于前两项之和 def memo(func): cache = {}#闭包 def wrap(*args): if args not in ...
- python—第三库的安装方法
Windows系统下安装第三方Python库的三种方法: 1.使用easy_install命令安装 一般在安装完Python后再C:\Python27\Scripts 目录下有 easy_instal ...
- oracle开发学习篇之集合运算符以及集合异常捕获
--取出集合;长度 declare type list_nested ) not null; v_all list_nested := list_nested('a','b','c','d','c', ...