模拟android拨号器的实现

AndroidManifest.xml清单文件:

<?xml version="1.0"encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="cn.class3g.activity"

android:versionCode="1"

android:versionName="1.0">

<uses-sdk android:minSdkVersion="10"/>

<uses-permission android:name="android.permission.CALL_PHONE"/>

<application

android:icon="@drawable/ic_launcher"

android:label="@string/app_name">

<activity

android:label="@string/app_name"

android:name=".PhoneActivity">

<intent-filter >

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

</activity>

</application>

</manifest>

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/input_info"/>

<EditText

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:id="@+id/phone_number"

/>

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:id="@+id/dial_btn"

android:text="@string/dial_caotion"

/>

</LinearLayout>

strings.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_info">请输入号码</string>

<string name="dial_caotion">拨打</string>

</resources>

PhoneActivity.java类:

packagecn.class3g.activity;

importandroid.app.Activity;

importandroid.content.Intent;

importandroid.net.Uri;

importandroid.os.Bundle;

importandroid.view.View;

import android.view.View.OnClickListener;

importandroid.widget.Button;

importandroid.widget.EditText;

public classPhoneActivity extends Activity {

EditText numberEt;

Button dialBtn;

public void onCreate(BundlesavedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

findViews();

dialBtn.setOnClickListener(newOnClickListener() {

publicvoid onClick(View v) {

//调用系统的拨号服务实现电话拨打功能

Stringphone_number = numberEt.getText().toString();

phone_number= phone_number.trim();

if(phone_number!=null&&!phone_number.equals("")){

//封装一个拨打电话的intent,并且将电话号码包装成一个Uri对象传入

Intentintent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+phone_number));

PhoneActivity.this.startActivity(intent);

}

}

});

}

public void findViews(){

numberEt= (EditText) this.findViewById(R.id.phone_number);

dialBtn= (Button) this.findViewById(R.id.dial_btn);

}

}


拨号器的实现_第1张图片

更多相关文章

  1. Unity同步加载Android里的StreamingAssets里的文件
  2. android webview 下载文件
  3. AndroidManifest.xml文件详解(activity)(一)
  4. Android 实现windows文件资源管理器
  5. android 根据Uri获取文件绝对路径
  6. 重命名sd卡中的文件名

随机推荐

  1. Android获取设备信息
  2. 【Android】使用MediaCodec硬编码实现视
  3. Android窗口为弹出框样式
  4. android 系统自带主题样式及自定义主题样
  5. ListView 常用属性
  6. Android安卓41个开源项目
  7. 有关XML的点击状态背景图的设置
  8. 改写ListView样式
  9. 书单目录
  10. Android(安卓)Environment 常量含义