自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
手機帳戶建議
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
在 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
標記電話帳戶。系統就能在撥號應用程式中向使用者傳達這項資訊。
舉例來說,如果使用者已將裝置設定為使用工作 SIM 卡,以便與工作 Google 帳戶中的所有聯絡人通訊,服務應將電話帳戶標示為 REASON_USER_SET
,並將 shouldAutoSelect
設為 true,讓撥號程式略過選取對話方塊,並自動使用電話帳戶撥打電話。
如要瞭解其他建議,請參閱 PhoneAccountSuggestion
。
Dialer
當通話進入 STATE_SELECT_PHONE_ACCOUNT
狀態時,撥號器必須使用 PhoneAccountSuggestion
提供的資訊來處理 EXTRA_SUGGESTED_PHONE_ACCOUNTS
。
停用服務
如要針對特定電信業者自訂導入方式,您可以使用 setComponentEnabledSetting
啟用或停用服務。如果停用,系統就不會查詢服務。
系統 UI 實作
視導入方式而定,您可能需要變更系統 UI。舉例來說,如果您想讓使用者指定所有撥打給特定聯絡人的電話皆由特定電話帳戶撥打,就必須為裝置實作自訂設定流程和設定 UI。
驗證
如要驗證導入作業,請執行下列 CTS 測試:
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-27 (世界標準時間)。"],[],[],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)"]]