CallRedirectionService实现不起作用 [英] CallRedirectionService Implementation not working

查看:52
本文介绍了CallRedirectionService实现不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android Q 引入了 CallRedirectionService API-似乎第三方应用程序可以使用它的一种方式是取消呼叫并通过VoIP重新路由-本质上是拦截电话.

Android Q has introduced CallRedirectionService API - seems like one of the way 3rd party apps can use it is to cancel calls and reroute them over VoIP - essentially intercepting the phone calls.

我正在尝试如下实现此类

I was trying to implement this class as below

public class CallMonitorService extends CallRedirectionService {
    private static final String TAG = "CallMonitorService";

    public CallMonitorService() {
    }

    @Override
    public void onPlaceCall(Uri uri, PhoneAccountHandle phoneAccountHandle, boolean b) {
        Log.e(TAG, "onPlaceCall:### ");
    }


}

如您所见,我覆盖了 onPlaceCall ,它是 CallRedirectionService 中的抽象方法,并且仅保留一条日志语句来检查/测试此回调方法钩子是否被调用Android框架.

As you can see I am overriding onPlaceCall which is abstract method in the CallRedirectionService and simply keeping a log statement to check/test if this callback method hook is invoked by Android framework.

我在Manifest.xml中以及以下内容中添加了此服务,这是 CallRedirectionService

I added this service in my Manifest.xml as well as below, which is what is documented in the Source code of CallRedirectionService class

<service
                android:name=".CallMonitorService"
                android:permission="android.permission.BIND_REDIRECTION_SERVICE"
                android:enabled="true"
                android:exported="true">
            <intent-filter>
                <action android:name="android.telecom.CallRedirectionService"/>
            </intent-filter>
        </service>

我的猜测是,当Android系统发出去电时,此 onPlaceCall 会被调用,然后我们可以编写自定义代码以对去电进行进一步的操作.不能100%地确定 CallRedirectionService 是否应该工作-顺便说一下,developer.android.com中没有可用的示例来说明如何实现 CallRedirectionService 这写.我在我的 build.gradle

My Guess is that when Android system places a outgoing call this onPlaceCall will be invoked and then we can write our custom code to do further action on the outgoing call. Am not 100% sure if this is how CallRedirectionService is supposed to work - By the way there is no example available in developer.android.com for how to implement CallRedirectionService as of this writing. I set both minSdkVersion 29 targetSdkVersion 29 in my build.gradle

无论何时拨打电话-服务内的 onPlaceCall 都不会被调用.

However when the call is made - the onPlaceCall inside my Service is not getting invoked.

我正在使用Android Q Emulator进行测试,因为我没有运行Android Q的Android手机对此进行测试-无法通过拨打模拟电话在Android Emulator上进行测试,或者我还缺少什么?

I am using Android Q Emulator for testing as i do not have Android phone running Android Q to test this - can this be not tested on Android emulator by placing a emulated phone call or What else Am I missing?

推荐答案

问题是,目前文档不完整,文档中的示例不正确.要解决此问题,需要在AndroidManifest中进行更改

The problem is that at the moment documentation is not full and sample in documentation is not correct. To fix this, in your AndroidManifest it is needed to change

android:permission="android.permission.BIND_REDIRECTION_SERVICE"

android:permission="android.permission.BIND_CALL_REDIRECTION_SERVICE"

此权限被错误地写入了 https://developer的google文档中.android.com/reference/android/telecom/CallRedirectionService.html 当前.

This permission is incorrectly written inside the google documentation for https://developer.android.com/reference/android/telecom/CallRedirectionService.html currently.

此外,还要求用户允许您的应用程序扮演此角色.在Google文档中,此部分目前不存在:

Also, it is required to ask user to allow your application play this role. In google documentation this part missing at the moment :

 RoleManager roleManager = null;
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) {
        roleManager = (RoleManager) getSystemService(Context.ROLE_SERVICE);

        Intent intent = roleManager.createRequestRoleIntent(RoleManager.ROLE_CALL_REDIRECTION);
        startActivityForResult(intent, 1);}

这篇关于CallRedirectionService实现不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆