package com.lingzhuo.dialer;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button bt=(Button) findViewById(R.id.bt_call);
//给按钮设置点击侦听事件
bt.setOnClickListener(new Mylistener());
}
class Mylistener implements OnClickListener{
//按钮被点击时,调用此方法
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
//System.out.println("点击拨号");
//获得用户输入的号码
EditText et=(EditText) findViewById(R.id.et_text);
String phonenum=et.getText().toString();
//我们需要告诉系统我们的动作:我要打电话
//创建意图对象
Intent intent=new Intent();
//把动作封装到意图对象当中
intent.setAction(Intent.ACTION_CALL);
//设置打给谁
intent.setData(Uri.parse("tel:"+phonenum));
//把动作告诉系统
<LinearLayout 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"
tools:context=".MainActivity"
android:orientation="vertical"
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="请输入号码"
<EditText
android:id="@+id/et_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
<requestFocus android:layout_width="wrap_content"
</EditText>
<Button
android:id="@+id/bt_call"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="拨号"
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.lingzhuo.dialer"
android:versionCode="1"
android:versionName="1.0"
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17"
<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.lingzhuo.dialer.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>