android 简单打电话程序
来源:互联网 发布:海文网络计划 编辑:程序博客网 时间:2024/05/18 02:07
完成android拨打电话程序只需简单几步即可完成。
第一步:
创建工程,在layout.xml文件中添加 EditText 和Button 控件
第二步:
在activity中声明控件并初始化(findViewById)
第三步:
为button添加响应事件 button.setOnclickListener(new View.onClickListener() {});
第四步:
在click中使用Intent 将拨号消息转给Intent.action_call 系统自带的拨号程序
第五步:
在manifest.xml文件中加入拨打电话的权限声明
整个工程涉及到的代码如下:
manifest.xml文件
<span style="font-family:Comic Sans MS;font-size:18px;"><?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.huawei.dialphone" android:versionCode="1" android:versionName="1.0" > <uses-permission android:name="android.permission.CALL_PHONE"/> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.huawei.dialphone.MainActivity" 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></span>
layout.xml文件内容:
<span style="font-family:Comic Sans MS;font-size:18px;"><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" tools:context=".MainActivity" > <EditText android:id="@+id/phone" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:ems="10" android:inputType="phone" > <requestFocus /> </EditText> <Button android:id="@+id/dial" android:text="@string/_dial" android:layout_height="wrap_content" android:layout_width="wrap_content" > </Button></LinearLayout></span>
activity类中的代码如下:
<span style="font-family:Comic Sans MS;font-size:18px;">package com.huawei.dialphone;import android.app.Activity;import android.content.Intent;import android.net.Uri;import android.os.Bundle;import android.view.Menu;import android.view.View;import android.widget.Button;import android.widget.EditText;public class MainActivity extends Activity {private Button dialButton;private EditText phoneNum; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); dialButton = (Button)findViewById(R.id.dial); phoneNum = (EditText)findViewById(R.id.phone); dialButton.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View arg0) {String phoneNumText = phoneNum.getText().toString();if(( phoneNumText != null) && (!"".equals(phoneNumText.trim()))){ // Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+phoneNumText)); Intent intent = new Intent(); intent.setAction(Intent.ACTION_CALL); intent.setData(Uri.parse("tel:" + phoneNumText)); startActivity(intent); } }}); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }</span>
这样就完成了一个简单的拨号程序。
0 0
- android 简单打电话程序
- Android 实现简单打电话
- Android:简单打电话 APP
- android打电话的程序
- Android 打电话程序
- Android简单的打电话程序的实现_学员原创
- 一个简单的打电话程序
- Android模拟打电话程序实现
- android模拟打电话程序实现
- Android虚拟打电话程序实现
- Android模拟打电话程序实现
- android 打电话程序的实现
- 使用Android开发打电话程序
- Android中简单的打电话应用
- 使用Android开发打电话程序详细
- Android模似打电话程序实现
- Android模似打电话程序实现
- android模拟打电话的应用小程序
- php vim 配置
- BNUOJ 44580 Araleii & Bill的冠名权争夺战 again
- spring mvc参数绑定
- linux TCP数据包重传过程----小结
- 配置一个高效的PHP开发环境Vim
- android 简单打电话程序
- nginx负载均衡
- LayoutTransition 容器布局动画
- ListView
- ExtJs 入门教程七[登陆窗体Demo:Login]
- ListView优化方案的几点解析
- hdu1892See you~
- LEETCODE: Restore IP Addresses
- 新的一年新的开始