Android电话拨号器(实例)

因为应用要使用手机的电话服务,所以要在清单文件AndroidManifest.xml中添加电话服务权限:

<?xml version="1.0"encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

     package="cn.itcast.action"

     android:versionCode="1"

     android:versionName="1.0">

     略....

   <uses-sdk android:minSdkVersion=“6" />

   <uses-permission android:name="android.permission.CALL_PHONE"/>

</manifest>

界面布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    <TextView  
    android:layout_width="fill_parent" android:layout_height="wrap_content" 
    android:text="@string/inputmobile"/>
    
    <EditText android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:id="@+id/mobile"/>
    
    <Button android:layout_width="wrap_content" android:layout_height="wrap_content"
    android:text="@string/button"
    android:id="@+id/button"/>
</LinearLayout>

LinearLayout (线性布局)、AbsoluteLayout(绝对布局)、RelativeLayout(相对布局)、TableLayout(表格布局)、FrameLayout(帧布局)

Activity:

 
 
Activity:
public class DialerAction extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button button = (Button)findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener(){
	public void onClick(View v) {
	        EditText editText = (EditText)findViewById(R.id.mobile);
	        Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+ editText.getText()));
	       DialerAction.this.startActivity(intent);
	}
        });
    }
}




你可能感兴趣的:(Android电话拨号器(实例))