【Android】Android开发初学者实现拨打电话的功能,拨打电话app小demo实现
作者:程序员小冰,GitHub主页:https://github.com/QQ986945193
新浪微博:http://weibo.com/mcxiaobing
首先先给大家看一下最终实现的效果:
其实这个案例的demo实在是太简单了。不过此功能也是非常强大,用处挺多的,
就像所谓的蚂蚁虽小,五脏俱全。我们可以用它集成在我们的app中。
拨打客服电话之类的。所以下面看代码吗,首先我们写好布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:id="@+id/et_phone_num"
android:layout_width="match_parent"
android:layout_height="60dp"
android:hint="请输入手机号码" />
<Button
android:id="@+id/btn_call_phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="点击拨打电话" />
</LinearLayout>
然后java代码中实现拨打电话的功能
`package davidappcheckupdate.qq986945193.com.callphonedavidapp;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
/**
* @author :程序员小冰
* @新浪微博 :http://weibo.com/mcxiaobing
* @GitHub:https://github.com/QQ986945193
* @CSDN博客: http://blog.csdn.net/qq_21376985
* @交流Qq :986945193
*/
public class MainActivity extends AppCompatActivity {
private EditText etPhone;
private Button btnPhone;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etPhone = (EditText) findViewById(R.id.et_phone_num);
btnPhone = (Button) findViewById(R.id.btn_call_phone);
btnPhone.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (etPhone.getText().toString().trim() == null || etPhone.getText().toString().trim().equals("")) {
Toast.makeText(MainActivity.this, "对不起,电话不能为空", Toast.LENGTH_SHORT).show();
return;
} else if (etPhone.getText().toString().trim() != null && !(etPhone.getText().toString().trim().equals(""))) {
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"
+ etPhone.getText().toString().trim()));
if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
return;
}
startActivity(intent);
}
}
});
}
}
`
最后重要的一点就是,添加拨打电话的权限在AndroidManifest.xml:
<uses-permission android:name="android.permission.CALL_PHONE" />
好了,教程到此结束。想要源代码的请看下面下载链接:
(AndroidStudio版)github下载地址:
https://github.com/QQ986945193/CallPhoneDavidApp
(AndroidStudio版)git开源中国下载地址:
http://git.oschina.net/MCXIAOBING/CallPhoneDavidApp
(AndroidStudio版)CSDN免积分下载地址:
http://download.csdn.net/detail/qq_21376985/9623854
【Android】Android开发初学者实现拨打电话的功能,拨打电话app小demo实现的更多相关文章
- Android嵌入式开发初学者的几个注意点
一:首先你必须了解ARM平台 Android 移植与驱动核心开发,当然也可以是X86和其他的平台,不过其他平台的Android智能终端开发并不是很多. Android嵌入式智能操作系统是基于Linux ...
- 玩转Android Camera开发(二):使用TextureView和SurfaceTexture预览Camera 基础拍照demo
Google自Android4.0出了TextureView,为什么推出呢?就是为了弥补Surfaceview的不足,另外一方面也是为了平衡GlSurfaceView,当然这是本人揣度的.关于Text ...
- 【转】玩转Android Camera开发(三):国内首发---使用GLSurfaceView预览Camera 基础拍照demo
http://blog.csdn.net/yanzi1225627/article/details/33339965 GLSurfaceView是OpenGL中的一个类,也是可以预览Camera的,而 ...
- 玩转Android Camera开发(三):国内首发---使用GLSurfaceView预览Camera 基础拍照demo
GLSurfaceView是OpenGL中的一个类,也是能够预览Camera的,并且在预览Camera上有其独到之处. 独到之处在哪?当使用Surfaceview无能为力.痛不欲生时就仅仅有使用GLS ...
- Android开发---基本UI组件1:自动拨电话,自动上网,输入框不换行、只输数字、只输文本、只输密码
1.activity_main.xml 描述:构建一个按钮 <?xml version="1.0" encoding="utf-8"?> <L ...
- XE5开发Android程序调用电话相关功能(短信息和电话)
方法a.不使用Intent而是直接发短信. smsManager对应的Delphi代码应该是: uses Androidapi.JNI.JavaTypes,Androidapi.JNI.Telepho ...
- XE5开发Android程序调用电话相关功能(短信息和电话) [转]
其实都可以通过intent和URI调用系统功能.Windows程序员可以理解成是ShellExecute.这个是万金油.可以有调用各种功能.后面会介绍. 1.短信息.很简单 方法a.不使用Intent ...
- Android 学习第11课,android 实现拨打电话的功能
1. 先布局界面,界面采用线性垂直方式来布局 在layout 界面文件中 activity_main.xml 中 <LinearLayout xmlns:android="http:/ ...
- Android软件开发需要学什么
首先,需要学习哪些Android开发技术? Android的开发技术很多,在开始学习的时候不可能一次性全部学会,也没有必要一开始都全部学会,但是有些技术是非常常用的,需要在开始时打好基础,这些技术时: ...
随机推荐
- js 读取word和txt(react版) + 正则分割段落
show the code 前提:需要mammoth包~ import React, { useState, useReducer } from 'react'; import { Button, A ...
- linux的文件系统管理(ext4-tune2fs-e2fsck-xfs文件系统)
文件系统管理 文件系统是Linux系统存放文件的空间.文件系统的类型有很多种,CentOS支持多种文件系统,目前常用的是ext4和xfs文件系统.我们以ext4文件系统为例来说明对文件系统的管理. U ...
- Android MTK平台 客制化系统来电界面(屏蔽 InCallUI 提供接口给客户自行展示来电去电页面)
OS: Android 8.1 需求分析 1.禁止系统来电铃声,提供接口给客户自己播放铃声 2.禁止系统拉起来去电页面(InCallActivity),消息通知客户拉起自己的来去电页面 3.禁止来电消 ...
- 在不同网段使用 VLAN 通信 - SVI,单臂路由
在 VLAN 这篇文章中知道,设置 VLAN 目的是隔离大型的广播域,将其分成很小的广播域,从而更好的管理.但也就带来了一些问题:如流量不能在不同的 VLAN 间通信. 而为了解决这个问题,可以采用如 ...
- Qt编译出现cc1plus.exe: out of memory allocating 65536 bytes问题
今天编译Qt程序,出现这个问题: cc1plus.exe: out of memory allocating 65536 bytes 这个还没有遇到过,上网查了下.问题原因是资源文件过大. qt的资源 ...
- 节点操作 - DOM编程
1. 获取节点 1.1 直接获取节点 父子关系: element.parentNode element.firstChild/element.lastChild element.firstElemen ...
- MacOS下如何优雅的使用冰蝎
因为冰蝎也是使用 JAVA 写的跨平台应用程序,我们可以借助 macOS 自带的 自动操作 automator.app 来创建一个应用程序. 前言: 冰蝎是一种新型的Webshell连接工具,在日常的 ...
- Visual Studio Code中设置sftp同步代码到服务器
## **前言** - 绝对的大佬才会直接在Linux下用vim写代码,我等小白只能通过IDE来了,所以将代码同步到服务器上就很重要了.使用vs code设置好sftp就可以实现这一功能. - 设置之 ...
- 2020-07-31:给定一个二叉搜索树(BST),找到树中第K 小的节点。
福哥答案2020-07-31: BST 的中序遍历是升序序列.1.递归法.时间复杂度:O(N),遍历了整个树.空间复杂度:O(N),用了一个数组存储中序序列.2.迭代法.时间复杂度:O(H+k),其中 ...
- SpringMVC常见问题Error configuring application listener of class org.springframework.web.context.ContextLoaderListenejava.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
六月 20, 2018 9:43:34 下午 org.apache.catalina.core.StandardContext listenerStart 严重: Error configuring ...