Android手机拨打电话的开发实例
一部手机最常用的功能就是打电话和发短信了,在Android开发中我们如何通过程序拨打电话呢?本文就给出一个用Android手机拨打电话的简单的实例。
下面是开发此实例的具体步骤:
一、新建一个Android工程,命名为phoneCallDemo。
二、设计程序的界面,打开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:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="Please input the phoneNumer:"
- />
- <EditText
- android:id="@+id/et1"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:phoneNumber="true"
- />
- <Button
- android:id="@+id/bt1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Call Phone"
- />
- </LinearLayout>
三、增加拨打电话的权限,打开AndroidManifest.xml,修改代码如下:
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.android.test"
- android:versionCode="1"
- android:versionName="1.0">
- <application android:icon="@drawable/icon" android:label="@string/app_name">
- <activity android:name=".PhoneCallDemo"
- android:label="@string/app_name">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity> </application>
- <uses-sdk android:minSdkVersion="3" />
- <uses-permission android:name="android.permission.CALL_PHONE">
- </uses-permission>
- </manifest>
四、主程序phoneCallDemo.java代码如下:
- package com.android.test;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;
- import android.widget.Toast;
- public class PhoneCallDemo extends Activity {
- private Button bt;
- private EditText et;
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- //取得资源
- bt = (Button)findViewById(R.id.bt1);
- et = (EditText)findViewById(R.id.et1);
- //增加事件响应
- bt.setOnClickListener(new Button.OnClickListener(){ @Override
- public void onClick(View v) {
- //取得输入的电话号码串
- String inputStr = et.getText().toString();
- //如果输入不为空创建打电话的Intent
- if(inputStr.trim().length()!=0)
- {
- Intent phoneIntent = new Intent("android.intent.action.CALL",
- Uri.parse("tel:" + inputStr));
- //启动
- startActivity(phoneIntent);
- }
- //否则Toast提示一下
- else{
- Toast.makeText(PhoneCallDemo.this, "不能输入为空", Toast.LENGTH_LONG).show();
- }
- }
- });
- }
Android手机拨打电话的开发实例的更多相关文章
- android 自动拨打电话 挂断电话代码
页面布局文件代码 ( res下面的layout下面的activity_main.xml代码 ) <RelativeLayout xmlns:android="http://sche ...
- Android音乐播放器的开发实例
本文将引导大家做一个音乐播放器,在做这个Android开发实例的过程中,能够帮助大家进一步熟悉和掌握学过的ListView和其他一些组件.为了有更好的学习效果,其中很多功能我们手动实现,例如音乐播放的 ...
- Android 直接拨打电话界面
Android 拨号界面和直接拨打电话界面代码控制 //定义TAG为空 private static final String TAG = null; //定义Button的点击事件 tell.set ...
- H5 手机拨打电话与转到邮箱的标签属性
<a href="tel:电话号码"></a> <a href-"mailto:邮箱"></a> 说明:第一个标 ...
- 脚本控制向Android模拟拨打电话,发送短信,定位设置功能
做行为触发的时候要向模拟器实现拨打电话,发送短信,定位设置的的功能,可以很方便通过telnet localhost 5554实现. 写个脚本很快的搞定了.网上资料很多,脚本的很少,也所积点德啦. 写 ...
- 实现Android半透明Menu效果的开发实例
不知道大家是否用过天天动听,对于它界面上的半透明Menu效果,笔者感觉非常漂亮.下面是天天动听半透明Menu的截图,欣赏下吧: 感觉还不错吧?那么如何实现这种半透明Menu效果呢?本文就重点讨论并给出 ...
- Android 学习第11课,android 实现拨打电话的功能
1. 先布局界面,界面采用线性垂直方式来布局 在layout 界面文件中 activity_main.xml 中 <LinearLayout xmlns:android="http:/ ...
- h5唤醒手机拨打电话
jquery : $("#a").attr("href","tel:110");
- Android APP代码拨打电话、打开手机分享功能等隐式意图
Android APP拨打电话: Intent intent=new Intent(Intent.ACTION_DIAL,Uri.parse("tel:"+110)); start ...
随机推荐
- C++实现网格水印之调试笔记(二)
整理了一下要实现的论文Watermarking 3D Polygonal Meshes in the Mesh Spectral Domain,步骤如下: 嵌入水印 à 提取水印 à 优化(网格细分) ...
- Python面向对象2
方法 公共方法 私有方法 类方法 静态方法 #!usr/bin/python #coding:utf8 class Milo(): name = 'csvt' def fun1(self): prin ...
- (原创)spring mvc和jersey rest 组合使用时单例对像实例化两次的BUG及解决办法
项目中没用spring 的restTemplate 而是采用 jersey来做rest 的实现,一直用着,也没发现有什么不对,后来加入了,以quartz用硬编码方式实现,结果启动项目的时候报错 ,具体 ...
- GraphChi介绍
GraphChi介绍 最近在研究graphchi,它是一个在单机上处理图的一个很强大的框架. 给大家一些链接可以学习它: 论文:http://select.cs.cmu.edu/publication ...
- 使用matplotlib绘制带图例的图表
#coding=utf8 from pylab import * plt.figure(figsize=(8,10), dpi=50) plt.plot(do_tow2[28:508],do_prn2 ...
- Codevs No.3147 矩阵乘法2
2016-06-01 17:33:30 题目链接: 矩阵乘法2 (Codevs No.3147) 题目大意: 给定两个大小相同的正方形矩阵A,B.多次询问,每次求乘后矩阵的一个子矩阵所有元素的和. 解 ...
- AndroidAsync :异步Socket,http(client+server),websocket和socket.io的Android类库
AndroidAsync是一个用于Android应用的异步Socket,http(client+server),websocket和socket.io的类库.基于NIO,没有线程.它使用java.ni ...
- AVD设置屏幕大小
相关资料: 1.http://jingyan.baidu.com/article/fedf0737775d2835ac897700.html
- javaIO(05)字节流和字符流的区别
字节流和字符流的区别: 直接根据图片得出结论: 结论: 字节流在操作时本身不会用到缓存区,是在文件本身直接操作的,而字符流在操作时使用了缓存区,通过缓存区在操作文件: 所以在操作字符流的时候 ...
- AutoCAD.NET二次开发:创建自定义菜单的两种方法比较
目前我已经掌握的创建CAD菜单方法有两种: COM方式: http://www.cnblogs.com/bomb12138/p/3607929.html CUI方式: http://www.cnblo ...