Android拨号器的实现

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               

Android自带了拨号功能和拨号器,但是在很多的应用中,需要在自己的应用中集成拨号的功能,方便客户直接点击

就可以完成打电话,所以这样的调用Android拨号器的功能还是非常有实用价值的,下面我们来介绍一下Android拨号器

的实现。

调用Android自带的拨号功能其实我们是使用满足他的意图对象而实现调用的,下面我们首先来看一下主要的

Activity代码

package com.bird.phone;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 PhoneActivity extends Activity private EditText text;//寻找空间这种事情只需要做一次就够了    /** Called when the activity is first created. */    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);        text = (EditText) findViewById(R.id.mobile);//得到文本输入框        Button button = (Button) this.findViewById(R.id.button);//根据id寻找控件        button.setOnClickListener(new View.OnClickListener() {      @Override   public void onClick(View v) {    String mobileText = text.getText().toString();    Intent intent = new Intent();//创建一个意图对象,用来激发拨号的Activity    intent.setAction("android.intent.action.CALL");    intent.setData(Uri.parse("tel:"+mobileText));    startActivity(intent);//方法内部会自动添加类别,android.intent.category.DEFAULT   }  });//添加点击事件     }    /*    //创建内部类实现回调对象    private final class ButtonClick implements View.OnClickListener{  @Override  public void onClick(View v) {      String mobileText = text.getText().toString();   Intent intent = new Intent();//创建一个意图对象,用来激发拨号的Activity   intent.setAction("android.intent.action.CALL");   intent.setData(Uri.parse("tel:"+mobileText));   startActivity(intent);//方法内部会自动添加类别,android.intent.category.DEFAULT  }         }*/}


大部分介绍都放在了代码的注释上面,其实还是很简单的。

然后最主要的就是配置文件了

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.bird.phone"    android:versionCode="1"    android:versionName="1.0" >         <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8"/>     <uses-permission android:name="android.permission.CALL_PHONE"/>         <application        android:icon="@drawable/ic_launcher"        android:label="@string/app_name" >        <activity            android:name=".PhoneActivity"            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></manifest>

主要是权限问题
<uses-permission android:name="android.permission.CALL_PHONE"/>
调用拨号功能需要有权限调用拨号,这个东西会在用户安装这个应用的时候提示你是否允许他使用拨号的功能,好,下面就是一个
界面的问题了
main.xml页面文件如下
  1. <code class="language-html"><?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     android:orientation="vertical" >  
  6.   
  7.     <TextView  
  8.         android:layout_width="fill_parent"  
  9.         android:layout_height="wrap_content"  
  10.         android:text="@string/mobile" />  
  11.        
  12.     <EditText   
  13.         android:layout_width="fill_parent"  
  14.         android:layout_height="wrap_content"  
  15.         android:inputType="text"  
  16.         android:id="@+id/mobile"  
  17.        />  
  18.       
  19.     <Button   
  20.         android:layout_width="wrap_content"  
  21.         android:layout_height="wrap_content"  
  22.         android:text="@string/button"  
  23.         android:id="@+id/button"  
  24.         />  
  25. </LinearLayout></code>  
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" >    <TextView        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="@string/mobile" />      <EditText      android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:inputType="text"        android:id="@+id/mobile"       />        <Button         android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/button"        android:id="@+id/button"        /></LinearLayout>

然后是strings.xml
 
 
  1. <code class="language-html"><?xml version="1.0" encoding="utf-8"?>  
  2. <resources>  
  3.   
  4.     <string name="hello">Hello World, PhoneActivity!</string>  
  5.     <string name="app_name">Phone</string>  
  6.     <string name="mobile">请输入手机号</string>  
  7.     <string name="button">拨号</string>  
  8. </resources></code>  
<?xml version="1.0" encoding="utf-8"?><resources>    <string name="hello">Hello World, PhoneActivity!</string>    <string name="app_name">Phone</string> <string name="mobile">请输入手机号</string> <string name="button">拨号</string></resources>

好,至此一个简单的Android拨号器就完成了,功能虽小,但是使用的地方还是很多的.
 
 

           

给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow
这里写图片描述
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值