一部手机最常用的功能就是打电话和发短信了,在Android开发中我们如何通过程序拨打电话呢?本文就给出一个用Android手机拨打电话的简单的实例。

下面是开发此实例的具体步骤:

一、新建一个Android工程,命名为phoneCallDemo。

二、设计程序的界面,打开main.xml把内容修改如下:

XML/HTML代码
  1. <?xml version="1.0" encoding="utf-8"?>
  2.   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.   android:orientation="vertical"
  4.   android:layout_width="fill_parent"
  5.   android:layout_height="fill_parent"
  6.   >
  7.   <TextView
  8.   android:layout_width="fill_parent"
  9.   android:layout_height="wrap_content"
  10.   android:text="Please input the phoneNumer:"
  11.   />
  12.   <EditText
  13.   android:id="@+id/et1"
  14.   android:layout_width="fill_parent"
  15.   android:layout_height="wrap_content"
  16.   android:phoneNumber="true"
  17.   />
  18.   <Button
  19.   android:id="@+id/bt1"
  20.   android:layout_width="wrap_content"
  21.   android:layout_height="wrap_content"
  22.   android:text="Call Phone"
  23.   />
  24.   </LinearLayout>

三、增加拨打电话的权限,打开AndroidManifest.xml,修改代码如下:

XML/HTML代码
  1.  <?xml version="1.0" encoding="utf-8"?>
  2.   <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3.   package="com.android.test"
  4.   android:versionCode="1"
  5.   android:versionName="1.0">
  6.   <application android:icon="@drawable/icon" android:label="@string/app_name">
  7.   <activity android:name=".PhoneCallDemo"
  8.   android:label="@string/app_name">
  9.   <intent-filter>
  10.   <action android:name="android.intent.action.MAIN" />
  11.   <category android:name="android.intent.category.LAUNCHER" />
  12.   </intent-filter>
  13.   </activity> </application>
  14.   <uses-sdk android:minSdkVersion="3" />
  15.   <uses-permission android:name="android.permission.CALL_PHONE">
  16.   </uses-permission>
  17.   </manifest>

四、主程序phoneCallDemo.java代码如下:

Java代码
  1. package com.android.test;import android.app.Activity;
  2.   import android.content.Intent;
  3.   import android.net.Uri;
  4.   import android.os.Bundle;
  5.   import android.view.View;
  6.   import android.widget.Button;
  7.   import android.widget.EditText;
  8.   import android.widget.Toast;
  9. public class PhoneCallDemo extends Activity {
  10.   private Button bt;
  11.   private EditText et;
  12.   public void onCreate(Bundle savedInstanceState) {
  13.   super.onCreate(savedInstanceState);
  14.   setContentView(R.layout.main);
  15.   //取得资源
  16.   bt = (Button)findViewById(R.id.bt1);
  17.   et = (EditText)findViewById(R.id.et1);
  18.   //增加事件响应
  19.   bt.setOnClickListener(new Button.OnClickListener(){ @Override
  20.   public void onClick(View v) {
  21.   //取得输入的电话号码串
  22.   String inputStr = et.getText().toString();
  23.   //如果输入不为空创建打电话的Intent
  24.   if(inputStr.trim().length()!=0)
  25.   {
  26.   Intent phoneIntent = new Intent("android.intent.action.CALL",
  27.   Uri.parse("tel:" + inputStr));
  28.   //启动
  29.   startActivity(phoneIntent);
  30.   }
  31.   //否则Toast提示一下
  32.   else{
  33.   Toast.makeText(PhoneCallDemo.this, "不能输入为空", Toast.LENGTH_LONG).show();
  34.   }
  35.   }
  36.   });
  37.   }

Android手机拨打电话的开发实例的更多相关文章

  1. android 自动拨打电话 挂断电话代码

    页面布局文件代码  (  res下面的layout下面的activity_main.xml代码 ) <RelativeLayout xmlns:android="http://sche ...

  2. Android音乐播放器的开发实例

    本文将引导大家做一个音乐播放器,在做这个Android开发实例的过程中,能够帮助大家进一步熟悉和掌握学过的ListView和其他一些组件.为了有更好的学习效果,其中很多功能我们手动实现,例如音乐播放的 ...

  3. Android 直接拨打电话界面

    Android 拨号界面和直接拨打电话界面代码控制 //定义TAG为空 private static final String TAG = null; //定义Button的点击事件 tell.set ...

  4. H5 手机拨打电话与转到邮箱的标签属性

    <a href="tel:电话号码"></a> <a href-"mailto:邮箱"></a> 说明:第一个标 ...

  5. 脚本控制向Android模拟拨打电话,发送短信,定位设置功能

    做行为触发的时候要向模拟器实现拨打电话,发送短信,定位设置的的功能,可以很方便通过telnet localhost  5554实现. 写个脚本很快的搞定了.网上资料很多,脚本的很少,也所积点德啦. 写 ...

  6. 实现Android半透明Menu效果的开发实例

    不知道大家是否用过天天动听,对于它界面上的半透明Menu效果,笔者感觉非常漂亮.下面是天天动听半透明Menu的截图,欣赏下吧: 感觉还不错吧?那么如何实现这种半透明Menu效果呢?本文就重点讨论并给出 ...

  7. Android 学习第11课,android 实现拨打电话的功能

    1. 先布局界面,界面采用线性垂直方式来布局 在layout 界面文件中 activity_main.xml 中 <LinearLayout xmlns:android="http:/ ...

  8. h5唤醒手机拨打电话

    jquery  :  $("#a").attr("href","tel:110");

  9. Android APP代码拨打电话、打开手机分享功能等隐式意图

    Android APP拨打电话: Intent intent=new Intent(Intent.ACTION_DIAL,Uri.parse("tel:"+110)); start ...

随机推荐

  1. HDU 5379 Mahjong tree

    题意:在一棵有n个节点的树上放编号从1到n的麻将,要求每个点的儿子节点之间的编号连续,每棵子树内的编号连续. 解法:手推一组样例之后就可以得到如下结论然后从根节点一边讨论一边搜就好了. 当一个节点只有 ...

  2. Oracle数据库导出

    一. pl/SQL方式 1.打开plsql,找到工具栏,导出表

  3. lightoj 1023

    题意:让你输出前N个大写字母的前K个排列,按字典序,很水,直接dfs. #include<cstdio> #include<string> #include<cstrin ...

  4. 查看系统或者Jmeter的Properties

    工作台-非测试元件-Property Display,可以显示系统或者Jmeter的Properties

  5. 【ActiveX】实现安全接口

    转自:http://www.cnblogs.com/carekee/articles/1772201.html 感谢原作者! ActiveX控件打包成cab后,在脚本中调用中时,要保证控件的安全性才能 ...

  6. 从python的yield说起

    前段时间在读trac 中wiki模块的源码的时候,发现了很多地方都使用了yiled这一关键词, 感觉是在需要返回某个值的地方通过yield来代替return, 不是很明白其用法,所以仔细研究下. 一个 ...

  7. Backbone.js developer 武汉 年薪8w-10w

    1.   精通Backbone.js 2.   熟练Ajax.NoSQL.RESTful APIs 3.   了解Pusher.com和 Parse.com 4.   具有良好的沟通能力,学习能力,敬 ...

  8. HDU5778 abs

    http://acm.hdu.edu.cn/showproblem.php?pid=5778 思路:只有平方质因子的数,也就是这题所说的   y的质因数分解式中每个质因数均恰好出现2次  满足条件的数 ...

  9. 一起刷LeetCode3-Longest Substring With Repeating Characters

    拖延症太严重了TAT,真心要处理一下这个问题了,感觉很不好! --------------------------------------------------------------------- ...

  10. [Hive - LanguageManual] Alter Table/Partition/Column

    Alter Table/Partition/Column Alter Table Rename Table Alter Table Properties Alter Table Comment Add ...