我正在尝试使用本指南实现与电信服务的互连: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
}