一、注册
1 <uses-permission android:name="android.permission.CALL_PHONE"/>
二、activity_main文件:
1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 tools:context=".MainActivity" > 6 7 <Button 8 android:id="@+id/callbtn" 9 android:layout_width="match_parent" 10 android:layout_height="wrap_content" 11 android:text="132" /> 12 13 </RelativeLayout>
三、Activity文件
1 package com.example.call_phone; 2 3 import android.app.Activity; 4 import android.content.Intent; 5 import android.net.Uri; 6 import android.os.Bundle; 7 import android.view.View; 8 import android.view.View.OnClickListener; 9 import android.widget.Button; 10 11 public class MainActivity extends Activity { 12 13 Button callbtn; 14 @Override 15 protected void onCreate(Bundle savedInstanceState) { 16 super.onCreate(savedInstanceState); 17 setContentView(R.layout.activity_main); 18 callbtn = (Button) findViewById(R.id.callbtn); 19 callbtn.setOnClickListener(new OnClickListener() { 20 21 @Override 22 public void onClick(View v) { 23 // TODO Auto-generated method stub 24 Intent intent = new Intent( 25 "android.intent.action.CALL", 26 Uri.parse("tel:"+callbtn.getText().toString()) 27 ); 28 startActivity(intent); 29 } 30 }); 31 } 32 33 34 }