Android开发之路(三)---模拟打电话的实现
来源:互联网 发布:mac book 和linux 编辑:程序博客网 时间:2024/05/21 23:00
Android开发之路(三)---模拟打电话的实现
A ndroid 开发是一件十分有意思的事情,模拟打电话的实现就是一件十分有意思的事情,自己的虚拟机给自己的虚拟机实现打电话功能。下面就介绍一下模拟打电话是怎么样实现的。
首先先建一个Android Project Phone
应先在values中的String.xml文件中来定义字符串和数值
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="input_info">请输入你要拨打的号码</string>//定义的是拨打的号码
<string name="button_caption">拨打</string> //是一button按钮来触及拨打的
</resources>
然后在Layout文件夹下的main.xml文件来设置界面在其中的代码是
<?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="wrap_content"
android:baselineAligned="false"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/input_info"
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/phone_number"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text = "@string/button_caption"
android:id="@+id/dial_btn"
/>
</LinearLayout>
在其中定义了界面,生成的界面就如图所示
接下来就是要学我们的程序的源代码了,在Phone中写的代码是
package cn.csdn.PhoneActivity;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class PhoneActivity extends Activity {
/** Called when the activity is first created. */
EditText numberEt;
Button dialBtn;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findViews();
dialBtn.setOnClickListener(myListener);
}
private void findViews() {
// TODO Auto-generated method stub
numberEt=(EditText) this.findViewById(R.id.phone_number);
dialBtn=(Button) this.findViewById(R.id.dial_btn);
}
private OnClickListener myListener=new Button.OnClickListener(){
public void onClick(View v) {
//调用系统的拨号服务实现电话拨打功能
String phone_number = numberEt.getText().toString();
phone_number = phone_number.trim();
if(phone_number != null && !phone_number.equals("")){
//封装一个拨打电话的intent,并且将电话号码包装成一个Uri对象传入
Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+phone_number));
PhoneActivity.this.startActivity(intent);
}
}
};
}
最后要注意的就是要在AndroidManifest.xml文件中要添加用户约束,那样才能打电话呢,在其中要选择Uses Permission 添加android.permission.CALL_PHONE方法
这样才能实现打电话的功能
- Android开发之路(三)---模拟打电话的实现
- Android模拟打电话的实现:
- Android学习笔记(三) 之模拟打电话
- Android模拟打电话功能的实现
- Android模拟打电话程序实现
- android模拟打电话程序实现
- Android模拟打电话程序实现
- Android成长之路-打电话功能的实现
- 两个android模拟器实现打电话发短信的模拟状态
- 两个android模拟器实现打电话发短信的模拟状态
- android 模拟器 实现 打电话 发短信的模拟状态
- 两个android模拟器实现打电话发短信的模拟状态
- Android开发之打电话功能
- Android模拟打电话应用程序实现分析
- android开发实现打电话的两种效果
- android模拟打电话的应用小程序
- android 打电话程序的实现
- Android模拟打电话
- 游戏开发的小决窍
- Linux命令整理(一)
- LINUX学习笔记6——使用GCC编译器
- jQuery的HTML操作
- LINUX学习笔记7——使用GDB程序调试工具
- Android开发之路(三)---模拟打电话的实现
- poj3984--BFS
- Android Mms专题之:Mms概览介绍
- KMP算法C语言的实现
- 交叉工具链制作至尊宝典
- hdu 1312
- LINUX学习笔记8——Makefile工程管理
- Android Binder设计与实现(3) – 设计篇
- 虚拟机Linux----操作系统的安装