使用Android开发打电话程序
来源:互联网 发布:淘宝上那家衣服质量好 编辑:程序博客网 时间:2024/05/16 10:14
今天开发了我的第一个Android程序--打电话。
因为是小程序所以我按照的设计步骤是 1.设计界面。2.设计Activity。3.业务层代码。逐步实现。
- <?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="@string/hello"
- />
- <EditText
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:id="@+id/telphone"
- />
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/btn"
- android:id="@+id/btnButton"
- />
- </LinearLayout>
其中需要注意的是:"android:id="@+id/btnButton"其中id就是按钮的id,定义的btnButton会自动在R.java中生成。
android:text="@string/hello" 中的hello是在项目res/values下的strings.xml中定义的string,内容自己添加。
2. Activity中的代码如下:
package com.example.phonecall;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;import android.app.Activity;import android.view.Menu;public class HelloWorld extends Activity {EditText text;Button btn; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //根据id查找用户拨打的号码 text = (EditText)findViewById(R.id.telphone); //根据id查找按钮 btn = (Button)findViewById(R.id.btnButton); //将拨打按钮绑定到事件上 btn.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {//定义Intent对象Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+text.getText().toString()));//启动Activity传输IntentHelloWorld.this.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; } }这里需要特别提醒的是通过id查找按钮或文本框时是到R.java文件中查找相应的内部类中的常量
3. strings.xml
<?xml version="1.0" encoding="utf-8"?><resources> <string name="app_name">PhoneCall</string> <string name="action_settings">Settings</string> <string name="hello_world">Hello world!</string> <string name="hello">拨出号码:</string> <string name="btn">拨打</string></resources>
4. 添加打电话权限AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.phonecall"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.phonecall.HelloWorld"
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>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.phonecall"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.phonecall.HelloWorld"
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>
- 使用Android开发打电话程序
- 使用Android开发打电话程序详细
- android使用系统程序打电话发短信
- android打电话的程序
- android 简单打电话程序
- Android 打电话程序
- Android模似打电话程序实现 - Android移动开发技术文章
- Android使用系统打电话
- Android模拟打电话程序实现
- android模拟打电话程序实现
- Android虚拟打电话程序实现
- Android模拟打电话程序实现
- android 打电话程序的实现
- Android开发之打电话功能
- Android模似打电话程序实现
- Android模似打电话程序实现
- android模拟打电话的应用小程序
- Android初入门(一)打电话程序
- android创建动态表单
- mongodb查询
- 一步一步教你做ios推送 pem证书制作 php推送
- IOS检测版本更新
- IOS开发之登录界面
- 使用Android开发打电话程序
- 求素数
- java程序性能优化
- cup基础知识。。
- STL string
- poj 2430 Lazy Cows 状压dp
- 物理内存管理(页管理)
- MOS管配合单片机控制+5V电压的通断
- 一天一点学习Linux之如何学习Linux