Android拨打电话号功能

在本篇博文中将为大家提供两种用代码实现调起电话簿,打电话功能,其实很简单,只是添加一个权限一个方法的事

1、添加权限

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

2、调起拨号页面,不拨打电话

private void callPhone(String phone) {
        Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phone));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }

3、不调起拨号页面,直接拨打电话

private void callPhone(String phone) {
		Intent intent=new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+phone));
		startActivity(intent);
	}

剩下就是在哪里需要,方法就在哪里调用就可以了,亲身尝试,绝对实用

猜你喜欢

转载自blog.csdn.net/jing_80/article/details/83991529
今日推荐