现在的位置: 首页 > 综合 > 正文

android调用拨打电话接口

2018年06月06日 ⁄ 综合 ⁄ 共 805字 ⁄ 字号 评论关闭
 
1 实现思路:
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);
			}
		}
    });
}
 
2  增加拨打电话的权限,在manifest中修改:
<uses-sdk android:minSdkVersion="7"/>
<uses-permission android:name="android.permission.CALL_PHONE"/>

抱歉!评论已关闭.