android实现拨打电话

main.xml

[xhtml]  view plain copy print ?
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:orientation="vertical"  
  4.     android:layout_width="fill_parent"  
  5.     android:layout_height="fill_parent"  
  6.     >  
  7. <TextView    
  8.     android:layout_width="fill_parent"   
  9.     android:layout_height="wrap_content"   
  10.     android:text="@string/hello"  
  11.     />  
  12.     <TextView  
  13.     android:layout_width="fill_parent"   
  14.     android:layout_height="wrap_content"   
  15.     android:text="@string/inputphonenumber"  
  16.     />  
  17.     <EditText  
  18.     android:id="@+id/phonenumber"  
  19.     android:layout_width="fill_parent"   
  20.     android:layout_height="wrap_content"   
  21.     android:phoneNumber="true"  
  22.     />  
  23.     <Button  
  24.     android:id="@+id/btn_call"  
  25.     android:layout_width="wrap_content"   
  26.     android:layout_height="wrap_content"   
  27.     android:text="@string/call"  
  28.     />  
  29. </LinearLayout>  
 

AndroidManifest.xml

[xhtml]  view plain copy print ?
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
  3.       package="com.wide.phone"  
  4.       android:versionCode="1"  
  5.       android:versionName="1.0">  
  6.     <uses-sdk android:minSdkVersion="8" />  
  7.     <!--添加可以向外拨打电话的权限  -->  
  8.     <uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>  
  9.     <application android:icon="@drawable/icon" android:label="@string/app_name">  
  10.         <activity android:name=".phoneAcitivity"  
  11.                   android:label="@string/app_name">  
  12.             <intent-filter>  
  13.                 <action android:name="android.intent.action.MAIN" />  
  14.                 <category android:name="android.intent.category.LAUNCHER" />  
  15.             </intent-filter>  
  16.         </activity>  
  17.     </application>  
  18. </manifest>  
 

phoneActivity.java

[java]  view plain copy print ?
  1. package com.wide.phone;  
  2. import android.app.Activity;  
  3. import android.content.Intent;  
  4. import android.net.Uri;  
  5. import android.os.Bundle;  
  6. import android.view.View;  
  7. import android.view.View.OnClickListener;  
  8. import android.widget.Button;  
  9. import android.widget.EditText;  
  10. public class phoneAcitivity extends Activity {  
  11.     /** Called when the activity is first created. */  
  12.     @Override  
  13.     public void onCreate(Bundle savedInstanceState) {  
  14.         super.onCreate(savedInstanceState);  
  15.         setContentView(R.layout.main);  
  16.        
  17.         Button btn_call = (Button) findViewById(R.id.btn_call);  
  18.           
  19.         btn_call.setOnClickListener(new OnClickListener() {  
  20.             public void onClick(View v) {  
  21.                 // TODO Auto-generated method stub  
  22.                 EditText et_phonenumber = (EditText)findViewById(R.id.phonenumber);  
  23.                 String number = et_phonenumber.getText().toString();  
  24.                 //用intent启动拨打电话  
  25.                 Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+number));  
  26.                 startActivity(intent);  
  27.             }  
  28.         });  
  29.     }  
  30. }  

发布了7 篇原创文章 · 获赞 0 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/u012913972/article/details/16960153