注意:文章中$$符号只有一个,因程序问题提交后变成了两个。

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();
  }
  }
  });
  }
good 39

发表评论

文明评论,重在参与

103楼 游客53606:
Android开发实例简单拨打电话_Android开发_wap站长之家 - 领先的移动互联网建站平台
<a href=“http://www.gyd9869t88v3ccr2o1y636lway99u3u4s.org/“>aojhidmioip</a>
ojhidmioip http://www.gyd9869t88v3ccr2o1y636lway99u3u4s.org/
uojhidmioip
07-08 04:16
用著作权法来保护软件是否真的有 07-28
杀毒软件:只在搞娱乐,从未杀过 07-28
小谈高通反垄断 07-28
印度将推出百元智能机 山寨厂商 07-28
高通垄断之痛:不是国产手机大而 07-28
一张图读懂阿里巴巴眼花缭乱资本 07-28
滴滴打车副总裁张晶离职 高层换 07-28
小米官网明日首发小米4 预约即 07-28
如何勾引马云马化腾花钱买你公司 07-28
云智慧成为2014 Web性能 07-28
顺丰试水微信扫码支付:发快递无 07-28
从Facebook看百度的移动 07-28
返回Android开发-返回首页
首页 社区 工具 关于 网址
切换:1.0/2.0-电脑-//
2009-2025 版权所有 wap123.cn