1.其实就是对Intent 的ACTION进行参数设置。

在manifest中药设置打电话的权限:

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

xml:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" > <EditText
android:id="@+id/phoneNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="phone" /> <Button
android:id="@+id/btn_call"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="打电话" /> </LinearLayout>

Activity:

 public class MainActivity extends Activity {

     private EditText Number;

     private Button btn;

     @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Number = (EditText) findViewById(R.id.phoneNumber);
btn = (Button) findViewById(R.id.btn_call);
btn.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
if (Number.getText().toString().trim().equals("")) {
Number.setError("电话号码不能为空");
} else { Intent i = new Intent("android.intent.action.CALL", Uri
.parse("tel:" + Number.getText().toString().trim()));
startActivity(i);
} }
}); }
}
05-08 08:23