自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
电话账号建议
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
在 Android 10 中,电话账号建议服务允许在用户拨打电话时向其显示电话账号建议。例如,如果用户的设备装有多个 SIM 卡并且网内通话费率较低,则此服务会首先识别被呼叫者的运营商,然后建议使用与被呼叫者位于同一网络的 SIM 卡。
电话账号建议服务是可选的,可以在搭载 Android 10 或更高版本的设备上实现。
实现
如需实现电话账号建议,请在 /system/priv-app/
中的应用内实现一项 PhoneAccountSuggestionService
服务。如果实现了多项 PhoneAccountSuggestionService
,平台不会查询该服务。该服务必须声明 android.Manifest.permission.BIND_PHONE_ACCOUNT_SUGGESTION_SERVICE
权限。
如果用户拨打电话,而未对被呼叫者设置默认拨出电话账号和首选电话账号,电信服务会绑定到 PhoneAccountSuggestionService
以收集有关账号的信息,平台会调用 onAccountSuggestionRequest(String number)
,并挂起外拨电话进程。
PhoneAccountSuggestionService
必须使用 onAccountSuggestionRequest(String number)
返回的号码来调用 suggestPhoneAccounts(String number, List<PhoneAccountSuggestion> suggestions)
。
调用 suggestPhoneAccounts(String number, List<PhoneAccountSuggestion> suggestions)
时,电信服务会返回建议的电话账号列表。然后,拨号器必须显示建议的电话账号列表,供用户选择从哪个账号发起呼叫。
PhoneAccountSuggestion
如需提供建议,请使用 PhoneAccountSuggestion 类。例如,如果服务确定被呼叫者与设备中的某张 SIM 卡位于同一运营商网络,该服务应该用 REASON_INTRA_CARRIER
标记该电话账号。然后,可通过拨号器将这一信息传达给用户。
再如,如果用户将设备配置为对 Google 工作账号中的所有联系人使用工作 SIM 卡,则服务应该用 REASON_USER_SET
标记该电话账号,并将 shouldAutoSelect
设置为 true,以允许拨号器绕过选择对话框并自动使用该电话账号拨打电话。
如需了解其他建议,请参阅 PhoneAccountSuggestion
。
Dialer
当呼叫进入 STATE_SELECT_PHONE_ACCOUNT
状态后,拨号器必须使用来自 PhoneAccountSuggestion
的信息处理 EXTRA_SUGGESTED_PHONE_ACCOUNTS
。
停用服务
如需自定义特定运营商的实现,您可以使用 setComponentEnabledSetting
启用或停用该服务。平台不会查询已停用的服务。
系统界面实现
您可能需要更改系统界面,具体取决于您的实现。例如,若要允许用户指定对特定联系人的所有呼叫均用特定电话账号进行,您必须为设备实现一个自定义设置流程和设置界面。
验证
如需验证您的实现,请运行以下 CTS 测试:
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-03-26。
[null,null,["最后更新时间 (UTC):2025-03-26。"],[],[],null,["# Phone account suggestion\n\nIn Android 10, the phone account suggestion service\nallows suggestions for phone\naccounts to be shown to users when making a call. For example, for users with a\ndevice with multiple SIMs and lower rates for intra-network calls, this\nservice first identifies the callee's carrier and then suggests using the SIM on\nthe same network as the callee.\n\nThe phone account suggestion service is optional and can be implemented on\ndevices running Android 10 or higher.\n\nImplementation\n--------------\n\nTo implement phone account suggestions, implement *one*\n[`PhoneAccountSuggestionService`](https://android.googlesource.com/platform/frameworks/base/+/android16-release/telecomm/java/android/telecom/PhoneAccountSuggestionService.java)\nservice in an app that is located in `/system/priv-app/`. The service isn't\nqueried if more than one `PhoneAccountSuggestionService`is implemented. The\nservice must declare the\n`android.Manifest.permission.BIND_PHONE_ACCOUNT_SUGGESTION_SERVICE` permission.\n\nWhen a user makes an outgoing call where neither the\n[default outgoing phone account](https://developer.android.com/reference/android/telecom/TelecomManager.html#getDefaultOutgoingPhoneAccount(java.lang.String))\nnor the\n[preferred phone account](https://developer.android.com/reference/android/provider/ContactsContract.DataColumns.html#PREFERRED_PHONE_ACCOUNT_COMPONENT_NAME)\nis set for the callee, the telecom service binds to\n`PhoneAccountSuggestionService` to gather information about the accounts,\n[`onAccountSuggestionRequest(String number)`](https://android.googlesource.com/platform/frameworks/base/+/android16-release/telecomm/java/android/telecom/PhoneAccountSuggestionService.java#98)\nis called, and the outgoing call process is suspended.\n\n`PhoneAccountSuggestionService` must call\n[`suggestPhoneAccounts(String number, List\u003cPhoneAccountSuggestion\u003e suggestions)`](https://android.googlesource.com/platform/frameworks/base/+/android16-release/telecomm/java/android/telecom/PhoneAccountSuggestionService.java#110)\nwith the number returned by\n[`onAccountSuggestionRequest(String number)`](https://android.googlesource.com/platform/frameworks/base/+/android16-release/telecomm/java/android/telecom/PhoneAccountSuggestionService.java#98).\n\nWhen\n[`suggestPhoneAccounts(String number, List\u003cPhoneAccountSuggestion\u003e suggestions)`](https://android.googlesource.com/platform/frameworks/base/+/android16-release/telecomm/java/android/telecom/PhoneAccountSuggestionService.java#110)\nis called, the telecom service returns a list of suggested phone accounts. The\ndialer must then display the list of suggested phone accounts for the user to\nchoose from to make the call.\n\n### PhoneAccountSuggestion\n\nTo make suggestions, use the\n[PhoneAccountSuggestion](https://android.googlesource.com/platform/frameworks/base/+/android16-release/telecomm/java/android/telecom/PhoneAccountSuggestion.java)\nclass.\nFor example, if the service determines the callee is on the same carrier as one\nof the SIMs in the device, the service should mark the phone account with\n[`REASON_INTRA_CARRIER`](https://android.googlesource.com/platform/frameworks/base/+/android16-release/telecomm/java/android/telecom/PhoneAccountSuggestion.java#46).\nThis information can then be conveyed to the user in the dialer.\n\nFor example, in a situation where the user has configured the device to use\na work SIM for all contacts\nin a work Google Account, the service should mark the phone account with\n[`REASON_USER_SET`](https://android.googlesource.com/platform/frameworks/base/+/android16-release/telecomm/java/android/telecom/PhoneAccountSuggestion.java#58)\nand set\n[`shouldAutoSelect`](https://android.googlesource.com/platform/frameworks/base/+/android16-release/telecomm/java/android/telecom/PhoneAccountSuggestion.java#121)\nto true to allow the dialer to bypass the selection dialog and automatically\nplace the call using the phone account.\n\nFor information on other suggestions, see\n[`PhoneAccountSuggestion`](https://android.googlesource.com/platform/frameworks/base/+/android16-release/telecomm/java/android/telecom/PhoneAccountSuggestion.java).\n\n### Dialer\n\nWhen the call enters the\n[`STATE_SELECT_PHONE_ACCOUNT`](https://android.googlesource.com/platform/frameworks/base/+/android16-release/telecomm/java/android/telecom/Call.java#84)\nstate, the dialer must use the information from\n[`PhoneAccountSuggestion`](https://android.googlesource.com/platform/frameworks/base/+/android16-release/telecomm/java/android/telecom/PhoneAccountSuggestion.java)\nto handle\n[`EXTRA_SUGGESTED_PHONE_ACCOUNTS`](https://android.googlesource.com/platform/frameworks/base/+/android16-release/telecomm/java/android/telecom/Call.java#136).\n\n### Disable the service\n\nTo customize your implementation for specific carriers, you can enable or\ndisable the service using\n[`setComponentEnabledSetting`](https://developer.android.com/reference/android/content/pm/PackageManager.html#setComponentEnabledSetting(android.content.ComponentName,%20int,%20int)%60).\nThe service is not queried if disabled.\n\n### System UI implementation\n\nDepending on your implementation, changes to the system UI may be required. For\nexample, to allow users to specify that all calls to a specific contact are\nmade from a specific phone account, you must implement a customized set up flow\nand settings UI for the device.\n\nValidation\n----------\n\nTo validate your implementation, run the following CTS tests:\n\n- [`/cts/tests/tests/telecom/src/android/telecom/cts/PhoneAccountSuggestionServiceTest.java`](https://android.googlesource.com/platform/cts/+/android16-release/tests/tests/telecom/src/android/telecom/cts/PhoneAccountSuggestionServiceTest.java)\n- [`/cts/tests/tests/telecom/src/android/telecom/cts/PhoneAccountSuggestionTest.java`](https://android.googlesource.com/platform/cts/+/android16-release/tests/tests/telecom/src/android/telecom/cts/PhoneAccountSuggestionTest.java)"]]