4Manuals

  • PDF Cloud HOME

如何在未经许可的情况下使用Android中的意图拨打电话? Download

    如何在Android中使用WebRTC缩放相机 Android 10,API29:在应用程序文件夹中使用C ++库编写文件会使应用程序崩溃 如何将动态值传递给渐变xml 加载数据并推送到未显示的RecyclerView中 调用Model类的函数时出现java.lang.NullPointerException 从网络加载图像时,“接收到完整的报头之前关闭连接 Ionic 3错误:“缺少文件google-services.json。没有它,Google Services插件将无法运行。”在离子科尔多瓦建立/准备Android androidx.appcompat.view.menu.MenuItemImpl无法转换为android.widget.TextView 从Firebase发送推送通知不起作用 Ljava / applet / Applet上的Android LDAP / NoClassDefFoundError;

我的应用使用android权限action_dial。 如何更改代码,使其不需要许可? 我需要能够打电话给没有权限的人

这是代码:

这篇文章里充满了代码,这不是我的错。


    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        // Older Version No need to request Permission
        String dial = "tel:" + phoneNo;
        fragment.startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse(dial)));
    } else {
        // Need to request Permission
        if (fragment.getActivity() != null) {
            if (ContextCompat.checkSelfPermission(fragment.getActivity(), Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
                fragment.requestPermissions(new String[]{
                        Manifest.permission.CALL_PHONE
                }, Constants.REQUEST_CODE__PHONE_CALL_PERMISSION);
            } else {
                String dial = "tel:" + phoneNo;
                fragment.startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse(dial)));
            }
        }
    }
}


                                             int[] grantResults, Fragment fragment, String phoneNo) {
    if (requestCode == Constants.REQUEST_CODE__PHONE_CALL_PERMISSION) {
        if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            callPhone(fragment, phoneNo);
        } else {
            Utils.psLog("Permission not Granted");
        }


    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        // Older Version No need to request Permission
        String dial = "tel:" + phoneNo;
        activity.startActivity(new Intent(Intent.ACTION_CALL, Uri.parse(dial)));
    } else {
        // Need to request Permission
        if (activity != null) {
            if (ContextCompat.checkSelfPermission(activity, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
                activity.requestPermissions(new String[]{
                        Manifest.permission.CALL_PHONE
                }, Constants.REQUEST_CODE__PHONE_CALL_PERMISSION);
            } else {
                String dial = "tel:" + phoneNo;
                activity.startActivity(new Intent(Intent.ACTION_CALL, Uri.parse(dial)));
            }
        }
    }

2 个答案:

答案 0 :(得分:0)

您可以这样做:

Intent intentDial = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + "123456789"));
context.startActivity(intentDial);

但是它将把用户导航到默认的呼叫拨号器应用程序并向其传递电话号码,因此用户应按“呼叫”按钮进行呼叫。它不会直接拨打电话。

答案 1 :(得分:0)

未经许可,无法进行直接通话。 您可以使用所需的号码在应用程序顶部打开拨号程序,用户接下来应单击绿色的呼叫按钮。 为此,请使用此代码

Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + phoneNumberStr));

startActivity(callIntent);



Similar searches
    Msgget失败:未实现功能 在Laravel Nova Vue组件中观看动态渲染的字段 get-pip.py中的语法无效,并且无法在窗口7中成功下载pip 用于C ++的Web程序集接口类型绑定? 如何从数据透视表中检索元素