我在将VoIP应用程序与安卓智能手表(任何型号)集成时遇到了问题。我们的应用程序使用的是安卓ConnectionService API。来电者的名字不会显示在手表的来电通知中--它只写“未知”或来电者id (4位分机),永远不会显示实际的应用程序联系人名(app联系人,而不是设备联系人)。但是,正常的GSM呼叫是正确显示的(它会根据联系人名称进行解析),而且,如果我的设备联系人打电话给我,他们的名字和化身也会被正确显示。
要指定名称,我使用的是android.telecom.Connection.setCallerDisplayName(displayName,TelecomManager.PRESENTATION_ALLOWED),但没有效果。
发布于 2022-09-27 10:35:03
我对三星齿轮智能手表也有同样的问题。您会看到“未知”,因为调用方的名称是根据设备联系人解析的(因此,常规GSM呼叫按预期工作)。解决办法如下:
displayName (呼叫者的名字)和address (呼叫者的电话号码)。地址是Uri,看起来可能像sip:1234567或tel:+1234567,这并不重要。displayName和phoneNumber创建临时联系。这里的phoneNumber应该是地址的Uri.schemeSpecificPart (:后面的部分)。还可以添加化身/图标。ContentProviderOperation.newInsert(Data.CONTENT_URI)
.withValueBackReference(Data.RAW_CONTACT_ID, 0)
.withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)
.withValue(StructuredName.GIVEN_NAME, displayName)
.build()ContentProviderOperation.newInsert(Data.CONTENT_URI)
.withValueBackReference(Data.RAW_CONTACT_ID, 0)
.withValue(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE)
.withValue(Phone.NUMBER, phoneNumber)
.build()添加此联系人后,
ConnectionService知道,现在有一个与您为VoIP调用创建的连接相对应的联系人。contactManager是执行上述操作的类,accountHandle是用于注册PhoneAccount (通过telecomManager.registerPhoneAccount())的android.telecom.AccountHandle,address是带有电话号码的Uri。contactManager.createOrUpdateTempContact(address.schemeSpecificPart, displayName)
telecomManager.addNewIncomingCall(accountHandle, bundleOf("key.call.address" to address))调用
ConnectionService::onCreateIncomingConnection()回调,在此函数中,您应该设置地址:override fun onCreateIncomingConnection(
connectionManagerPhoneAccount: PhoneAccountHandle?,
request: ConnectionRequest?
): Connection {
val newConnection = // Instantiate your Connection class implementation
request?.let{
newConnection.setAddress(request.extras.getParcelable("key.call.address") as? Uri, TelecomManager.PRESENTATION_ALLOWED)
newConnection.extras = request.extras
}
// Setting up newConnection further (set audioModeIsVoip, connectionProperties, etc.)
return newConnection
}在调用为answered/rejected.之后,您可以安全地删除临时联系人。
N.B.
我没有发布brevity.
ConnectionRequest.address的整个创建/更新/删除临时联系人代码,而是在onCreateIncomingConnection()中为我返回null,这就是为什么我在使用setCallerDisplayName()函数的extras.
https://stackoverflow.com/questions/61596102
复制相似问题