Android 调用 phone 号码侧边菜单

Android call phone number side menu

我正忙于制作我的第一个 android 应用程序,我希望创建以下选项: 当有人从 "activit_main_drawer.xml" 点击 "Contact us" 他们会直接打电话给 "phone number"

有没有人可以帮助我? :)

这就是 "Button" 的调用方式

    <item
        android:id="@+id/nav_belnu"
        android:icon="@drawable/ic_phone_square_solid"
        android:title="BEL nu" />

在你的按钮的onclick监听器里面,你可以这样进行,记得在你项目的manifest文件中添加调用权限:

private void makeCall(String phoneNumber){
        try {
                Intent intent = new Intent(Intent.ACTION_CALL);
                intent.setData(Uri.parse("tel:" + phoneNumber));
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {

                    return;
                }
                startActivity(intent);
            }catch (Exception e)
            {
                e.printStackTrace();
            }
}