首先如图:


新建一个Android工程,基于Anrdoid2.2模拟器创建

然后完善string.xml文件

<?xml version="1.0" encoding="utf-8"?><resources>    <string name="hello">Hello World, SharpPhoneActivity!</string>    <string name="app_name">SharpPhone</string><string name="mobile">请输入手机号</string>    <string name="button">拨打此号</string></resources>

然后是完善界面 修改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="fill_parent"    android:orientation="vertical" >    <TextView        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="@string/mobile" /><EditText       android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:id="@+id/phoneno" /><Button     android:layout_width="wrap_content"        android:layout_height="wrap_content"         android:text="@string/button"        android:id="@+id/button"    /></LinearLayout>

接着需要在Activity类处理信息

package com.sharpanroid.phone;import android.app.Activity;import android.content.Intent;import android.net.Uri;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.EditText;public class SharpPhoneActivity extends Activity {    /** Called when the activity is first created. */    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);        Button bt=(Button)this.findViewById(R.id.button);        bt.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {EditText phoneText=(EditText)findViewById(R.id.phoneno);/** * 获取手机号 */String phoneno=phoneText.getText().toString();if(null!=phoneno&&!"".equals(phoneno.trim())){/** * 数据通过Uri包封装 ,创建一个拨号意图 */Intent intent=new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+phoneno));startActivity(intent);}}});            }}
由于调用了打电话的服务,需要在AndroidManifest.xml 文件中进行引用

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.sharpanroid.phone"    android:versionCode="1"    android:versionName="1.0" >    <uses-sdk android:minSdkVersion="8" /><uses-permission android:name="android.permission.CALL_PHONE"/>    <application        android:icon="@drawable/ic_launcher"        android:label="@string/app_name" >        <activity            android:name=".SharpPhoneActivity"            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>

该功能看似简单,但也是基础,本文只为自己所积累。日后回看带来些帮助

下载地址为:

点击打开链接


更多相关文章

  1. 基于Android(安卓)Studio 的NDK之 “Hello,World!”
  2. Android(安卓)HIDL 中 hidl-gen使用
  3. android实现瀑布流加载图片
  4. ECLIPSE android 布局页面文件出错故障排除Exception raised dur
  5. Android(安卓)Studio上报错java.net.UnknownServiceException: C
  6. Android图片加载之认识bitmap的四种加载方式
  7. Error generating final archive: java.io.EOFException
  8. Android学习笔记:通过Android之Service实现文件断点续传下载
  9. android 文件合并打包 Error:Execution failed for task ':app:p

随机推荐

  1. Android(安卓)Handler详解
  2. 记录Android应用程序行为-peachbox
  3. Day6 快速学习OkHttp3的九大用法
  4. android webkit CSS3及Render初窥
  5. Android高手进阶教程(九)之----Android(
  6. android 音效处理(1)
  7. Android常见面试题
  8. Android学习系列(2)--App自动更新之通知
  9. Android(安卓)中的WiFi学习笔记----WIFI
  10. 【Android经典入门教程-上(bill译)】