使用系统拔号服务必须在AndroidManifest.xml中添加电话服务权限
AndroidManifest.xml
<?xml version="1.0" encoding="UTF-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.me.callphone"> <application> <activity android:name=".MainActivity" android:label="MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> </application> <uses-sdk android:minSdkVersion="3" /> <uses-permission android:name="android.permission.CALL_PHONE"/><!--加入权限--> </manifest>
MainActivity.java
package org.me.callphone; import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; public class MainActivity extends Activity { private EditText txtNo; private Button btnCall; /** Called when the activity is first created. */ @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main); txtNo=(EditText)findViewById(R.id.txtNo); btnCall=(Button)findViewById(R.id.btnCall); btnCall.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v){ Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+txtNo.getText()));//拔打电话Intent MainActivity.this.startActivity(intent); } }); } }