إدارة المكالمات باستخدام واجهة برمجة التطبيقات Telecom
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
يتناول هذا الدليل كيفية توجيه الصوت لأجهزة البلوتوث باستخدام
Telecom API وإعداد الاتصال
مكالمات VoIP اطّلِع على
دليل إنشاء تطبيقات للاتصال
قبل المتابعة.
من خلال استخدام ConnectionService
وConnection صفًا، يمكنك الوصول إليها
حالة الصوت وقائمة بأجهزة البلوتوث المتاحة، ويمكنك توجيه
الصوت إلى جهاز بلوتوث محدد.
اتصال VoIP وخدمة الاتصال
إنشاء صف VoIPConnection يمتد من
Connection تتحكّم هذه الفئة في حالة المكالمة الحالية. نظرًا لأن العمود
دليل إنشاء تطبيقات مكالمات
جعل هذا التطبيق مُدارًا ذاتيًا وضبط وضع الصوت لتقنية VoIP
التطبيق.
من خلال هذه العناصر المخصصة ConnectionConnectionService صفًا، أنت
يمكننا التحكم في الجهاز ونوع التوجيه الصوتي الذي تريد استخدامه أثناء
الاتصال.
الحصول على حالة الصوت الحالية
للحصول على حالة الصوت الحالية، اتصل
getCallAudioState()getCallAudioState()
يمكنك إرجاعه إذا كان الجهاز يبث المحتوى باستخدام البلوتوث أو سماعة الأذن أو عبر السلكية.
مكبّر الصوت
mAudioState=connection.getCallAudioState()
تم تغيير حالة التفعيل
الاشتراك في التغييرات في CallAudioState من خلال إلغاء
onCallAudioStateChanged()
وينبهك هذا الإجراء في حال حدوث أي تغييرات في الولاية.
استخدام المستوى 23 من واجهة برمجة التطبيقات والمستويات الأعلى
تفعيل
ROUTE_BLUETOOTH
بدون تحديد الجهاز باستخدام
setAudioRoute(int)
يؤدي هذا الإعداد التلقائي إلى ضبط الإعدادات التلقائية على الأجهزة الحالية والنشطة التي تتضمّن بلوتوث على نظام التشغيل Android 9 والإصدارات الأحدث.
setAudioRoute(CallAudioState.ROUTE_BLUETOOTH);
يخضع كل من المحتوى وعيّنات التعليمات البرمجية في هذه الصفحة للتراخيص الموضحّة في ترخيص استخدام المحتوى. إنّ 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,["# Manage calls using the Telecom API\n\nThis guide covers how to route audio for Bluetooth devices using the\n[Telecom API](/develop/connectivity/telecom) and set the connection for\nVoIP calls. Read the\n[Build a calling app](/develop/connectivity/telecom/selfManaged) guide\nbefore continuing.\n\nBy using the [`ConnectionService`](/reference/android/telecom/ConnectionService)\nand [`Connection`](/reference/android/telecom/Connection) classes, you can access\nthe audio state and a list of available Bluetooth devices, and can route\naudio to a selected Bluetooth device.\n\nVoIP Connection and ConnectionService\n-------------------------------------\n\nCreate a `VoIPConnection` class that extends from\n[`Connection`](/reference/android/telecom/Connection). This class controls the state of the current call. As the\n[Build a calling app](/develop/connectivity/telecom/selfManaged) guide\nstates, make this a self-managed application and set the audio mode for a VoIP\napplication. \n\n### Kotlin\n\n```kotlin\nclass VoIPConnection : Connection() {\n init {\n setConnectionProperties(PROPERTY_SELF_MANAGED)\n setAudioModeIsVoip(true)\n }\n}\n```\n\n### Java\n\n```java\npublic class VoIPConnection extends Connection {\n public VoIPConnection() {\n setConnectionProperties(PROPERTY_SELF_MANAGED);\n setAudioModeIsVoip(true);\n }\n}\n```\n\nNext, return an instance of this class in\n[`ConnectionService`](/reference/android/telecom/ConnectionService) when an\nincoming or outgoing call occurs. \n\n### Kotlin\n\n```kotlin\nclass VoIPConnectionService : ConnectionService() {\n override fun onCreateOutgoingConnection(\n connectionManagerPhoneAccount: PhoneAccountHandle,\n request: ConnectionRequest,\n ): Connection {\n return VoIPConnection()\n }\n}\n```\n\n### Java\n\n```java\npublic class VoIPConnectionService extends ConnectionService {\n @Override\n public Connection onCreateOutgoingConnection(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request) {\n return new VoIPConnection();\n }\n}\n```\n\nEnsure the manifest correctly points to the `VoIPConnectionService` class. \n\n \u003cservice android:name=\".voip.TelegramConnectionService\" android:permission=\"android.permission.BIND_TELECOM_CONNECTION_SERVICE\"\u003e\n \u003cintent-filter\u003e\n \u003caction android:name=\"android.telecom.ConnectionService\"/\u003e\n \u003c/intent-filter\u003e\n \u003c/service\u003e\n\nWith these custom [`Connection`](/reference/android/telecom/Connection) and\n[`ConnectionService`](/reference/android/telecom/ConnectionService) classes, you\ncan control which device and what type of audio routing you wish to use during a\ncall.\n\nGet the current audio state\n---------------------------\n\nTo get the current audio state, call\n[`getCallAudioState()`](/reference/android/telecom/Connection#getCallAudioState()).\n[`getCallAudioState()`](/reference/android/telecom/Connection#getCallAudioState())\nreturns if the device is streaming using Bluetooth, Earpiece, Wired, or\nSpeaker. \n\n mAudioState = connection.getCallAudioState()\n\nOn State Changed\n----------------\n\nSubscribe to changes in CallAudioState by overriding\n[`onCallAudioStateChanged()`](/reference/android/telecom/Connection#onCallAudioStateChanged(android.telecom.CallAudioState)).\nThis alerts you of any changes to the state. \n\n### Kotlin\n\n```kotlin\nfun onCallAudioStateChanged(audioState: CallAudioState) {\n mAudioState = audioState\n}\n```\n\n### Java\n\n```java\n@Override\npublic void onCallAudioStateChanged(CallAudioState audioState) {\n mAudioState = audioState;\n}\n```\n\nGet the current device\n----------------------\n\nGet the current active device using\n[`CallAudioState.getActiveBluetoothDevice()`](/reference/android/telecom/CallAudioState#getActiveBluetoothDevice()).\nThis function returns the active Bluetooth device.\n**Note:** This feature is only available in API level 28 and higher. \n\n### Kotlin\n\n```kotlin\nval activeDevice: BluetoothDevice = mAudioState.getActiveBluetoothDevice()\n```\n\n### Java\n\n```java\nBluetoothDevice activeDevice = mAudioState.getActiveBluetoothDevice();\n```\n\nGet Bluetooth devices\n---------------------\n\nGet a list of Bluetooth devices that are available for call audio routing using\n[`CallAudioState.getSupportedBluetoothDevices()`](/reference/android/telecom/CallAudioState#getSupportedBluetoothDevices()). \n\n### Kotlin\n\n```kotlin\nval availableBluetoothDevices: Collection =\n mAudioState.getSupportedBluetoothDevices()\n```\n\n### Java\n\n```java\nCollection availableBluetoothDevices = mAudioState.getSupportedBluetoothDevices();\n```\n\nRoute the call audio\n--------------------\n\n### Using API level 28 and higher (recommended)\n\nRoute the call audio to an available Bluetooth device using\n[`requestBluetoothAudio(BluetoothDevice)`](/reference/android/telecom/Connection#requestBluetoothAudio(android.bluetooth.BluetoothDevice)): \n\n requestBluetoothAudio(availableBluetoothDevices[0]);\n\n### Using API level 23 and higher\n\nEnable\n[`ROUTE_BLUETOOTH`](/reference/android/telecom/CallAudioState#ROUTE_BLUETOOTH)\nwithout specifying the device using\n[`setAudioRoute(int)`](/reference/android/telecom/Connection#setAudioRoute(int)).\nThis defaults routing to current, active bluetooth devices on Android 9 and higher. \n\n setAudioRoute(CallAudioState.ROUTE_BLUETOOTH);\n\n| **Note:** This step isn't required if the app already knows which Bluetooth device to route audio to."]]