我正在尝试使用本指南实现与电信服务的互连:https://developer.android.com/guide/topics/connectivity/telecom/
我已经可以在没有电信服务的情况下显示我自己的全屏来电UI,拨打和接听视频电话。所有我想与Telecomservice合作,只是告诉Android操作系统,我们的应用程序在特定时刻启动/停止视频通话,并接收来自其他通话应用程序的来电保留/非保留事件。
主要问题是:
1)addNewIncomingCall在传入调用的情况下什么都不做:onCreateIncomingConnection回调没有被触发(甚至onCreate回调我的ConnectionService根本没有被触发)。为什么没有启动连接服务?
2)在拨打电话的情况下,呼叫尝试用我们的用户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
}
看起来你想用self-managed connection service实现这个应用程序。
检查您是否拥有权限:
使用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);