安卓调用打电话程序

来源:互联网 发布:麻将编程算法 编辑:程序博客网 时间:2024/05/11 03:46
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Button button=(Button)findViewById(R.id.button);
    button.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
  EditText phoneText=(EditText)findViewById(R.id.mobile);
String phoneno=phoneText.getText().toString();
if(phoneno==null||"".equals(phoneno.trim()))
{
Toast.makeText(getApplicationContext(), "没有电话号码",
    Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(getApplicationContext(), "有电话号码"+phoneno,
    Toast.LENGTH_SHORT).show();
Intent intent=new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+phoneno));
startActivity(intent);
}
       
        });
    }
同时,我们需要增加拨打电话的权限,在manifest中修改:
<uses-sdk android:minSdkVersion="7"/>
<uses-permission android:name="android.permission.CALL_PHONE"/>
0 0