一部手机最常用的功能就是打电话和发短信了,在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. Ajax+PHP简单入门教程

    Ajax 由 HTML.JavaScript™ 技术.DHTML 和 DOM 组成,这一杰出的方法可以将笨拙的 Web 界面转化成交互性的 Ajax 应用程序.对于Ajax,最核心的一个对象是XMLH ...

  2. Oracle行列互换 横表和纵表

    /* 在实际使用sql工作中总会碰到将某一列的值放到标题中显示.就是总说的行列转换或者互换. 比如有如下数据: ID NAME KECHENG CHENGJI -- ---------- ------ ...

  3. wpa_cli调试工具的使用

    1: run wpa_supplicant first use the following command: wpa_supplicant -Dwext -iwlan0 -C/data/system/ ...

  4. Object类介绍

    一.Object类介绍

  5. javascript 面向对象制作坦克大战 (一)

    PS:这个坦克大战是在网上下的一段源码之后,自己进行的重写.   写这个的目的是为了巩固自己这段时间对js的学习.整理到博客上,算是对自己近端时间学习js的一个整理. 同时也希望可以帮助到学习js的园 ...

  6. Android的AutoCompleteTextView在API17高版本添加的setText函数在低版本系统居然能正常调用?官方文档是不是不靠谱了?

    官方文档:https://developer.android.com/reference/android/widget/AutoCompleteTextView.html#setText(java.l ...

  7. OC中两种单例实现方式

    OC中两种单例实现方式 写在前面 前两天探索了一下C++ 的单例,领悟深刻了许多.今天来看看OC中的单例又是怎么回事.查看相关资料,发现在OC中一般有两种实现单例的方式,一种方式是跟C++ 中类似的常 ...

  8. D3D11_USAGE使用

    MSDN文档链接:http://msdn.microsoft.com/en-us/library/windows/desktop/ff476259(v=vs.85).aspx 不得不同吐槽一点的是,你 ...

  9. 写i2c_client驱动的两种方式

    http://www.cnblogs.com/simonshi/archive/2011/02/24/1963426.html

  10. 机器学习中的数学(5)-强大的矩阵奇异值分解(SVD)及其应用

    版权声明: 本文由LeftNotEasy发布于http://leftnoteasy.cnblogs.com, 本文可以被全部的转载或者部分使用,但请注明出处,如果有问题,请联系wheeleast@gm ...