因为应用要使用手机的电话服务,所以要在清单文件 AndroidManifest.xml 中添 加电话服务权限 :
public class MainActivity extends Activity {
private EditText etPhone;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etPhone = (EditText) findViewById(R.id.etPhone);
}
public void click(View view)
{
String phone = etPhone.getText().toString().trim();
if(phone!=null && phone.length()>0)
{
//拨打电话
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+ phone));
startActivity(intent);
}
else
{
Toast.makeText(this, "号码不能为空!", 1).show();
}
}
}