android实现拨打电话

main.xml

  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

  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

  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.     } 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值