Android模似打电话程序实现 - Android移动开发技术文章
2014-05-22 23:57
766 查看
参考地址:http://www.verydemo.com/demo_c131_i173151.html
今天我们用Android写了一个小程序,实现了打电话。首先,先新建一个Android项目Phone,然后修改Layout下Values中的String.xml,代码如下:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, PhoneActivity!</string>
<string name="app_name">Phone</string>
<string name="input_into">请输入你要拨打的号码</string>
<string name="dial_caption">拨打</string>
</resources>
然后在main.xml中添加几个属性,代码如下:www.2cto.com
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/input_into" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/phone_number"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/dial_caption"
android:id="@+id/dial_btn"/>t
layout为布局,修改Main.xml的代码后将有如图的显示效果:
在R.Java中将自动生成如下代码:
public static final class drawable {
public static final int ic_launcher=0x7f020000;
}
public static final class id {
public static final int dial_btn=0x7f050001;
public static final int phone_number=0x7f050000;
}
public static final class string {
public static final int app_name=0x7f040001;
public static final int dial_caption=0x7f040003;
public static final int hello=0x7f040000;
public static final int input_into=0x7f040002;
}
在PhoneActivity.java文件中,有如下代码:
package cn.class3g.activity;
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 {
EditText numberEt;
Button dialBtn;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findViews();
dialBtn.setOnClickListener(myListener);
}
public void findViews(){
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 intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+phone_number));
PhoneActivity.this.startActivity(intent);
}
}
};
}
在AndroidManifest.xml中<application上方添加:
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.CALL_PHONE"/>
保存,模似打电话的程序就写完了,打开手机虚似机,右击项目名称,选Run As...—>Android Application运行,便可拨打电话了。
注:该程序需启动两个手机虚似机,以实现互相拨号。
运行后效果如下图:
摘自 LLLAZY520的专栏
今天我们用Android写了一个小程序,实现了打电话。首先,先新建一个Android项目Phone,然后修改Layout下Values中的String.xml,代码如下:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, PhoneActivity!</string>
<string name="app_name">Phone</string>
<string name="input_into">请输入你要拨打的号码</string>
<string name="dial_caption">拨打</string>
</resources>
然后在main.xml中添加几个属性,代码如下:www.2cto.com
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/input_into" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/phone_number"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/dial_caption"
android:id="@+id/dial_btn"/>t
layout为布局,修改Main.xml的代码后将有如图的显示效果:
在R.Java中将自动生成如下代码:
public static final class drawable {
public static final int ic_launcher=0x7f020000;
}
public static final class id {
public static final int dial_btn=0x7f050001;
public static final int phone_number=0x7f050000;
}
public static final class string {
public static final int app_name=0x7f040001;
public static final int dial_caption=0x7f040003;
public static final int hello=0x7f040000;
public static final int input_into=0x7f040002;
}
在PhoneActivity.java文件中,有如下代码:
package cn.class3g.activity;
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 {
EditText numberEt;
Button dialBtn;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findViews();
dialBtn.setOnClickListener(myListener);
}
public void findViews(){
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 intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+phone_number));
PhoneActivity.this.startActivity(intent);
}
}
};
}
在AndroidManifest.xml中<application上方添加:
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.CALL_PHONE"/>
保存,模似打电话的程序就写完了,打开手机虚似机,右击项目名称,选Run As...—>Android Application运行,便可拨打电话了。
注:该程序需启动两个手机虚似机,以实现互相拨号。
运行后效果如下图:
摘自 LLLAZY520的专栏
相关文章推荐
- 我的Android笔记(一)―― hello world程序结构分析 - Android移动开发技术文章
- 这篇文章给大家介绍Android开发四大组件之实现电话拦截和电话录音,涉及到android四大基本组件在程序中的应用,对android四大基本组件感兴趣的朋友可以参考下本篇文章
- Android模拟打电话程序实现
- Android虚拟打电话程序实现
- 个人安卓学习笔记---Android模拟打电话程序实现
- android开发技术文章荟萃【2011-10-21】
- 《人人都玩开心网:Ext JS+Android+SSH整合开发Web与移动SNS》销售排名第4,发篇ExtJS的文章(拖放树结点)庆祝下
- android开发技术文章荟萃【2011-10-14】
- android模拟打电话程序实现
- Android简单的打电话程序的实现_学员原创
- Flex开发中实现程序多语言的两篇文章
- android开发技术文章荟萃【2011-11-8】
- 使用Android开发打电话程序详细
- 用Android写了一个小程序,实现了打电话
- Android移动开发中通用技术整理
- Android模似打电话程序实现
- 产品安装包程序开发-技术实现介绍
- android开发技术文章荟萃【2011-10-24】
- Android模似打电话程序实现
- Android模拟打电话程序实现