1

我正在尝试使用本指南实现与电信服务的互连:https ://developer.android.com/guide/topics/connectivity/telecom/

我已经可以在没有电信服务的情况下显示我自己的全屏来电 UI,拨打和接听视频电话。所有,我想用 Telecomservice 做的,只是告诉 Android 操作系统,我们的应用程序正在特定时刻开始/停止视频通话,并接收来自其他呼叫应用程序的呼叫保持/未保持事件。

主要问题是:

1) addNewIncomingCall 在来电的情况下什么都不做:onCreateIncomingConnection 回调没有被触发(甚至我的 ConnectionService 的 onCreate 回调也没有被触发)。为什么连接服务没有启动?

2)在拨出电话的情况下,placeCall尝试使用我们的用户ID打开系统调用应用程序,将其称为电话或SIP号码。我可以在没有系统 UI 的情况下使用 placeCall 吗?

或者,如果我只是想通知系统有关视频通话,我可以使用 TelecomService 以外的其他选项吗?

连接创建如下:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        connection?.connectionProperties = Connection.PROPERTY_SELF_MANAGED
    }
    connection?.connectionCapabilities = Connection.CAPABILITY_HOLD and Connection.CAPABILITY_SUPPORT_HOLD
    connection?.setVideoState(VideoProfile.STATE_BIDIRECTIONAL)

拨打电话:

val telecomService = context.getSystemService(Context.TELECOM_SERVICE) as TelecomManager
                    try {
                        val uri = Uri.fromParts(PhoneAccount.SCHEME_SIP, teacherInfo.name, null)
                        telecomService.placeCall(uri, Bundle.EMPTY)
                    } catch (e: Throwable) {
                        e.printStackTrace()
                    }

接听电话:

val telecomService = applicationContext.getSystemService(Context.TELECOM_SERVICE) as TelecomManager
                      try {
                          Log.d("VideoCOnnection", "addNewIncomingCall")
                          telecomService.addNewIncomingCall(CallUtils.getAccountConnection(telecomService), Bundle.EMPTY)
                      } catch (e: Throwable) {
                          Log.d("VideoCOnnection", "crash")
                          e.printStackTrace()
                      }


@SuppressLint("MissingPermission")
fun getAccountConnection(teleconManager: TelecomManager) : PhoneAccountHandle? {
    return if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        val enabledAccounts = teleconManager.callCapablePhoneAccounts
        for(account in enabledAccounts) {
            if(account.componentName.className.equals(BindTelecomService::class.java.canonicalName)) {
                return account
            }
        }
        return null
    } else
        null
}
4

2 回答 2

2

看起来您想使用自我管理的连接服务来实现应用程序。

检查您是否有权限:

  • MANAGE_OWN_CALLS
  • READ_CALL_LOG
  • READ_PHONE_STATE

使用 CAPABILITY_SELF_MANAGED 注册电话帐户。

final String phoneAccountLabel = "myPhoneApp";

ComponentName connectionServiceName = new ComponentName(context.getApplicationContext(), TcService.class);
accountHandle = new PhoneAccountHandle(connectionServiceName, phoneAccountLabel);

PhoneAccount phoneAccount = telecom.getPhoneAccount(accountHandle);
if (phoneAccount == null) {
    PhoneAccount.Builder builder = PhoneAccount.builder(accountHandle, phoneAccountLabel);
    builder.setCapabilities(PhoneAccount.CAPABILITY_SELF_MANAGED);
    phoneAccount = builder.build();
    telecom.registerPhoneAccount(phoneAccount);
}

当您添加新的来电或去电时,您必须添加额外的 EXTRA_PHONE_ACCOUNT_HANDLE。

Uri uri = generateCallUri();
extras.putParcelable(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, accountHandle);
telecom.addNewIncomingCall(accountHandle, extras);

更新有一个例子

于 2019-04-30T09:23:02.427 回答
2

https://github.com/pranksterN1/TComTest https://stackoverflow.com/users/4466771/prankstern1发布了这个例子,它有效,但我仍然找不到,我的代码有什么问题:) 附加服务,例如示例中的 CallService 仅用于连接侦听,可替换为 GreenRobot 的事件总线或 Rx 以简化

于 2019-07-25T08:01:02.250 回答