【问题标题】:Accept incoming call is not working in marshmallow and noughat接听来电在棉花糖和牛轧糖中不起作用
【发布时间】:2019-02-09 10:59:22
【问题描述】:

我正在处理来电的应用来电屏幕。我无法在 android marshmallow 和 nougat API 级别 23 到 25 上接受来电。

公共无效acceptCall() { TelecomManager TelecomManager = null;

    //API level >=26
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        telecomManager = (TelecomManager) getApplicationContext().getSystemService(Context.TELECOM_SERVICE);
        telecomManager.acceptRingingCall();
    }

    //API level >=22
    else if (android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
        try {
            Runtime. getRuntime (). exec ("input keyevent " +
                    Integer.toString(KeyEvent.KEYCODE_HEADSETHOOK));
        } catch (IOException e) {
            // Runtime.exec(String) had an I/O problem, try to fall back
            String enforcedPerm = "android.permission.CALL_PRIVILEGED";
            Intent btnDown = new Intent(Intent.ACTION_MEDIA_BUTTON).putExtra(
                    Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN,
                            KeyEvent.KEYCODE_HEADSETHOOK));
            Intent btnUp = new Intent(Intent.ACTION_MEDIA_BUTTON).putExtra(
                    Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP,
                            KeyEvent.KEYCODE_HEADSETHOOK));

            context.sendOrderedBroadcast(btnDown, enforcedPerm);
            context.sendOrderedBroadcast(btnUp, enforcedPerm);
        }
    }


    //API level =23 || API=25||API=26
    if (android.os.Build.VERSION.SDK_INT == Build.VERSION_CODES.M || android.os.Build.VERSION.SDK_INT == Build.VERSION_CODES.N_MR1 ||
            android.os.Build.VERSION.SDK_INT == Build.VERSION_CODES.N) {
       //what code should i do here?

    }
}

【问题讨论】:

    标签: java android xml call


    【解决方案1】:

    查看TelecomManager的文档:https://developer.android.com/reference/android/telecom/TelecomManager#acceptRingingCall()

    请注意,对某些电信信息的访问是受权限保护的。您的应用程序无法访问受保护的信息或访问受保护的功能,除非它具有在其清单文件中声明的适当权限。如果权限适用,则会在方法说明中注明。

    acceptRingingCall() 的调用受到归类为“危险”的权限的保护。在 Android 版本 Marshmallow (API 23) 或更高版本上,您必须在运行时请求权限并将其包含在您的清单中。

    【讨论】:

      【解决方案2】:

      来自 Google 的更新:

      telecomManager.acceptRingingCall();
      telecomManager.acceptRingingCall(false);
      telecomManager.endCall();
      

      所有这三个命令在 Android Q 上都已弃用

      click to verify here

      【讨论】:

        猜你喜欢
        • 2017-07-22
        • 2017-01-06
        • 2017-06-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多