Android 点击实现打电话

来源:互联网 发布:淘宝卖家视频怎么上传 编辑:程序博客网 时间:2024/05/21 11:16
  1. import android.app.Activity;  
  2. import android.content.Intent;  
  3. import android.net.Uri;  
  4. import android.os.Bundle;  
  5. import android.view.Menu;  
  6. import android.view.View;  
  7. import android.view.View.OnClickListener;  
  8. import android.widget.Button;  
  9. import android.widget.TextView;  
  10.   
  11. public class MainActivity extends Activity {  
  12.   
  13.     private Button mCallButton;  
  14.     @Override  
  15.     protected void onCreate(Bundle savedInstanceState) {  
  16.         super.onCreate(savedInstanceState);  
  17.         setContentView(R.layout.activity_main);  
  18.         mCallButton = (Button) findViewById(R.id.btn_call);  
  19.         mCallButton.setOnClickListener(new OnClickListener() {  
  20.             @Override  
  21.             public void onClick(View v) {  
  22.                 // TODO Auto-generated method stub  
  23.                 //打给联通客服10010  
  24.                 Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:10010"));  
  25.                 startActivity(intent);  
  26.             }  
  27.         });  
  28.     }  
  29.   
  30. //  @Override  
  31. //  public boolean onCreateOptionsMenu(Menu menu) {  
  32. //      // Inflate the menu; this adds items to the action bar if it is present.  
  33. //      getMenuInflater().inflate(R.menu.main, menu);  
  34. //      return true;  
  35. //  }  
  36. //    
  37. //  public void clickHandler(View source){  
  38. //      TextView tv = (TextView) findViewById(R.id.show);  
  39. //      tv.setText("你好!现在时间:" + new java.util.Date());  
  40. //  }  
  41.       
  42. }  

activity_main.xml:

[html] view plain copy
 在CODE上查看代码片派生到我的代码片
  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.     android:paddingBottom="@dimen/activity_vertical_margin"  
  6.     android:paddingLeft="@dimen/activity_horizontal_margin"  
  7.     android:paddingRight="@dimen/activity_horizontal_margin"  
  8.     android:paddingTop="@dimen/activity_vertical_margin"  
  9.     tools:context=".MainActivity" >  
  10.   
  11.     <TextView  
  12.         android:id="@+id/show"  
  13.         android:layout_width="wrap_content"  
  14.         android:layout_height="wrap_content"  
  15.         android:layout_alignParentLeft="true"  
  16.         android:layout_alignParentTop="true"  
  17.         android:text="@string/hello_world" />  
  18.     <Button   
  19.         android:id="@+id/btn_click"  
  20.         android:layout_width="wrap_content"  
  21.         android:layout_height="wrap_content"  
  22.         android:layout_below="@id/show"  
  23.         android:text="点击我"  
  24.         android:onClick="clickHandler"/>  
  25.     <Button   
  26.         android:id="@+id/btn_call"  
  27.         android:layout_width="wrap_content"  
  28.         android:layout_height="wrap_content"  
  29.         android:layout_below="@id/btn_click"  
  30.         android:text="拨打电话"/>  
  31.   
  32. </RelativeLayout>  

AndroidManifest.xml:

[html] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     package="com.xiami.caipiao"  
  4.     android:versionCode="1"  
  5.     android:versionName="1.0" >  
  6.   
  7.     <uses-sdk  
  8.         android:minSdkVersion="8"  
  9.         android:targetSdkVersion="18" />  
  10.       
  11.     <uses-permission android:name="android.permission.CALL_PHONE"/>  
  12.       
  13.     <application  
  14.         android:allowBackup="true"  
  15.         android:icon="@drawable/ic_launcher"  
  16.         android:label="@string/app_name"  
  17.         android:theme="@style/AppTheme" >  
  18.         <activity  
  19.             android:name="com.xiami.caipiao.MainActivity"  
  20.             android:label="@string/app_name" >  
  21.             <intent-filter>  
  22.                 <action android:name="android.intent.action.MAIN" />  
  23.   
  24.                 <category android:name="android.intent.category.LAUNCHER" />  
  25.             </intent-filter>  
  26.         </activity>  
  27.     </application>  
  28.   
  29. </manifest>  
0 0
原创粉丝点击