Android实现打电话功能
2013-05-30 18:37
316 查看
初学安卓,入门的应用 。打电话。
新建Android 项目
layout 控件布局 :activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/phoneview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/lable_phone" />
<EditText
android:id="@+id/editview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/phoneview"
android:layout_below="@+id/phoneview"
android:layout_marginTop="14dp"
android:ems="10"
android:inputType="phone" >
<requestFocus />
</EditText>
<Button
android:id="@+id/butphone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editview"
android:layout_below="@+id/editview"
android:layout_marginTop="16dp"
android:text="@string/butphone" />
</RelativeLayout>
在AndroidManifest.xml 文件 中为其添加 打电话的 权限
你会在你发现在AndroidManifest.xml 文件 中有了一断这样的代码 其为打电话的 权限
//设置拨打电话 的权限
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission />
上面已经布局好 了。下面
然后在 MainActivity 中实现其功能:
public class MainActivity extends Activity {
private EditText editText;
private Button button_phone;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 设置显示pylt
setContentView(R.layout.activity_main);
//获取按钮组件
button_phone=(Button) findViewById(R.id.butphone);
//获取输入框组件
editText = (EditText) findViewById(R.id.editview);
//注册按钮事件
button_phone.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//获取号码
String phone_Num = editText.getText().toString();
//定义执行打电话的意图对象
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+phone_Num));
//执行意图
MainActivity.this.startActivity(intent);
//吐司的效果
Toast.makeText(MainActivity.this, "正在给"+phone_Num+"打电话",Toast.LENGTH_LONG).show();
}
});
}
}
然后把你写好的项目 发布到你的虚拟机上,Ok .
新建Android 项目
layout 控件布局 :activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/phoneview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/lable_phone" />
<EditText
android:id="@+id/editview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/phoneview"
android:layout_below="@+id/phoneview"
android:layout_marginTop="14dp"
android:ems="10"
android:inputType="phone" >
<requestFocus />
</EditText>
<Button
android:id="@+id/butphone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editview"
android:layout_below="@+id/editview"
android:layout_marginTop="16dp"
android:text="@string/butphone" />
</RelativeLayout>
在AndroidManifest.xml 文件 中为其添加 打电话的 权限
你会在你发现在AndroidManifest.xml 文件 中有了一断这样的代码 其为打电话的 权限
//设置拨打电话 的权限
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission />
上面已经布局好 了。下面
然后在 MainActivity 中实现其功能:
public class MainActivity extends Activity {
private EditText editText;
private Button button_phone;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 设置显示pylt
setContentView(R.layout.activity_main);
//获取按钮组件
button_phone=(Button) findViewById(R.id.butphone);
//获取输入框组件
editText = (EditText) findViewById(R.id.editview);
//注册按钮事件
button_phone.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//获取号码
String phone_Num = editText.getText().toString();
//定义执行打电话的意图对象
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+phone_Num));
//执行意图
MainActivity.this.startActivity(intent);
//吐司的效果
Toast.makeText(MainActivity.this, "正在给"+phone_Num+"打电话",Toast.LENGTH_LONG).show();
}
});
}
}
然后把你写好的项目 发布到你的虚拟机上,Ok .
相关文章推荐
- Android004_在跳出的页面上实现打电话和发短信的功能
- 基于Android重力传感器的编程——摇一摇打电话+旋转锁屏功能的实现
- Android模拟打电话功能的实现
- Android实现打电话功能
- 初学Android实现打电话的功能-使用Intent和AndroidManifset.xml中加入权限
- 【Android开发那点破事】实现打电话功能
- Android实现打电话的功能-使用Intent和AndroidManifset.xml中加入权限
- 初学Android实现打电话的功能-使用Intent和AndroidManifset.xml中加入权限
- Android 调用Android功能实现虚拟打电话程序
- Android成长之路-打电话功能的实现
- Android安卓带头像电话本实现打电话、发短信功能( ab54 源码)
- 基于Android重力传感器的编程——摇一摇打电话+旋转锁屏功能的实现
- Android 实现打电话功能demo
- Android实现打电话的功能-使用Intent和AndroidManifset.xml中加入权限
- Android实现打电话功能
- android自定义标签!(实现打电话的功能);
- Android实现发短信与打电话的功能
- Android实现打电话的功能-使用Intent和AndroidManifset.xml中加入权限
- 【Android开发那点破事】实现打电话功能
- Android----Intent,运用由android系统帮助匹配实现打电话、发送短信、打开网页、播放音乐、打开视频、打开图片、安装APK、通知栏消息、拍照上传头像等功能