android - Android Connection Service report outgoing call without showing native call UI?
问题描述
I have developed a voice calling app with android ConnectionServices and telecom framework.
I can show native call screen when receive incoming call notification from firebase and everything is fine. When I start an outgoing call I just want to report this call to Connection service so that if any call from gsm received it should report busy to caller. In callkit if you call reporting Outgoing call native callkit screen doesnt appears on my app screen but android shows native call. is it possible to make native screen invisible for outgoing calls?
my function to report outgoing call is below;
public void startCall(String number, String uuidString) {
UUID uuid = null;
if (uuidString != null) {
uuid = UUID.fromString(uuidString);
}
//TODO: allow name passed in as well
Log.d(TAG, "startCall number: $number");
Bundle extras = new Bundle();
Uri uri = Uri.fromParts(PhoneAccount.SCHEME_TEL, number, null);
Bundle callExtras = new Bundle();
callExtras.putString(Constants.EXTRA_CALL_NUMBER, number);
if (uuid != null) {
callExtras.putString(Constants.EXTRA_CALL_UUID, uuid.toString());
}
extras.putParcelable(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, voipUtilties.handle);
extras.putParcelable(TelecomManager.EXTRA_OUTGOING_CALL_EXTRAS, callExtras);
if (ActivityCompat.checkSelfPermission(Application.context, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
Log.d("VOIP_pLuGIN", "Yetki Yok");
return;
}else{
voipUtilties.telecomManager.placeCall(uri, extras);
}
}
and overrided outgoingConnection in Service class is like below.
@Override
public Connection onCreateOutgoingConnection(PhoneAccountHandle
connectionManagerPhoneAccount, ConnectionRequest request) {
Bundle extras = request.getExtras();
Connection outgoingCallConnection = null;
String number = request.getAddress().getSchemeSpecificPart();
String extrasNumber = extras.getString(EXTRA_CALL_NUMBER);
String displayName = extras.getString(EXTRA_CALLER_NAME);
boolean isForeground = VoipConnectionService.isRunning(this.getApplicationContext());
Log.d(TAG, "makeOutgoingCall:, number: " + number + ", displayName:" + displayName);
// Wakeup application if needed
if (!isForeground) {
Log.d(TAG, "onCreateOutgoingConnection: Waking up application");
//TODO:
}
outgoingCallConnection = createConnection(request);
outgoingCallConnection.setDialing();
outgoingCallConnection.setAudioModeIsVoip(true);
outgoingCallConnection.setCallerDisplayName(displayName, TelecomManager.PRESENTATION_ALLOWED);
// ️Weirdly on some Samsung phones (A50, S9...) using `setInitialized` will not display the native UI ...
// when making a call from the native Phone application. The call will still be displayed correctly without it.
if (!Build.MANUFACTURER.equalsIgnoreCase("Samsung")) {
outgoingCallConnection.setInitialized();
}
Log.d(TAG, "onCreateOutgoingConnection: calling");
final String uuid = outgoingCallConnection.getExtras().getString(EXTRA_CALL_UUID);
setAllOthersOnHold(uuid);
final String address = outgoingCallConnection.getExtras().getString(EXTRA_CALL_NUMBER);
Log.d(TAG,"Created call's uuid" + uuid);
return outgoingCallConnection;
}
any idea will be appriciated.
解决方案
我在我的项目中使用了这个包。在 VoipUtilities.kt 将 PhoneAccount 功能更改为 CAPABILITY_SELF_MANAGED 而不是 CAPABILITY_CALL_PROVIDER 和 VoipconnectionService.java 我将此代码块添加到 createConnection 函数解决了我的问题。
if((phoneAccount.getCapabilities() & PhoneAccount.CAPABILITY_SELF_MANAGED) == PhoneAccount.CAPABILITY_SELF_MANAGED) {
Log.d(TAG, "[VoiceConnectionService] PhoneAccount is SELF_MANAGED, so connection will be too");
connection.setConnectionProperties(Connection.PROPERTY_SELF_MANAGED);
}
推荐阅读
- memory - 每次写入缓冲区时是否应该调用`vkMapMemory`?
- python - 如何从python插入和检索存储在REDIS中的json?
- amazon-web-services - AWS GLUE ETL - 如何在新列中连接值
- sql - 如何在 Oracle SQL 中编写限制非所有者访问表的策略?
- c# - 使用带有 ORM 的 DTO 类时,C#8 中的可空引用类型
- amazon-web-services - 将安全 SSM 参数传递给嵌套的 CloudFormation 堆栈
- vue.js - Cpanel 上的 Laravel Vue 单页部署
- c++ - 为什么在 C++ 中禁止使用可变数组长度,尽管在声明后没有更改它?
- rust - 为返回的结果指定错误类型(在 SinkExt.with 的上下文中)
- javascript - 使用 AJAX 触发文件上传,无需表单或 Jquery