在本篇博文中将为大家提供两种用代码实现调起电话簿,打电话功能,其实很简单,只是添加一个权限和一个方法的事
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);
}
剩下就是在哪里需要,方法就在哪里调用就可以了,亲身尝试,绝对实用