نظرة عامة على البلوتوث
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
يشمل نظام Android الأساسي دعمًا لحزمة شبكة البلوتوث، والتي تتيح للجهاز تبادل البيانات لاسلكيًا مع الأجهزة الأخرى التي تتضمّن بلوتوث. يوفر إطار عمل التطبيق إمكانية الوصول إلى وظائف البلوتوث من خلال واجهات برمجة تطبيقات Bluetooth. تتيح واجهات برمجة التطبيقات هذه للتطبيقات إمكانية الاتصال بالأجهزة الأخرى التي تتضمّن بلوتوث، ما يفعِّل الميزات اللاسلكية من نقطة إلى نقطة وأخرى متعددة النقاط.
باستخدام واجهات برمجة التطبيقات Bluetooth API، يمكن لأي تطبيق إجراء ما يلي:
- ابحث عن أجهزة أخرى تتضمّن بلوتوث.
- يمكنك الاستعلام عن محوّل البلوتوث المحلي للأجهزة المقترنة التي تتضمّن بلوتوث.
- إنشاء قنوات بروتوكول RFCOMM
- الاتصال بالأجهزة الأخرى من خلال اكتشاف الخدمة
- نقل البيانات من وإلى الأجهزة الأخرى.
- إدارة عمليات ربط متعددة
يركّز هذا الموضوع على البلوتوث الكلاسيكي. تمثل تقنية البلوتوث الكلاسيكية الخيار المناسب لمزيد من العمليات التي تستهلك قدرًا أكبر من طاقة البطارية، والتي تشمل البث والتواصل بين الأجهزة. بالنسبة إلى أجهزة البلوتوث ذات المتطلبات المنخفضة للطاقة، يمكنك استخدام
اتصالات بلوتوث منخفض الطاقة.
يصف هذا المستند الملفات الشخصية للبلوتوث المختلفة ويشرح كيفية استخدام واجهات برمجة تطبيقات Bluetooth لتحقيق المهام الأربع الرئيسية اللازمة للتواصل باستخدام Bluetooth:
- جارٍ إعداد البلوتوث.
- العثور على الأجهزة المقترنة أو المتاحة في المنطقة المحلية
- ربط الأجهزة
- نقل البيانات بين الأجهزة.
للاطّلاع على عرض توضيحي لاستخدام واجهات برمجة التطبيقات Bluetooth، يُرجى الاطِّلاع على نموذج تطبيق Bluetooth Chat.
الأساسيّات
لنقل البيانات بين الأجهزة المزوّدة بتقنية البلوتوث، يجب أولاً تشكيل قناة اتصال باستخدام عملية إقران. جهاز واحد، جهاز قابل للاكتشاف،
يجعل نفسه متاحًا لطلبات الاتصال الواردة.
يعثر جهاز آخر على الجهاز القابل للاكتشاف باستخدام عملية اكتشاف الخدمة.
بعد قبول الجهاز القابل للاكتشاف طلب الإقران، يُكمِل الجهازان
عملية الربط التي يتبادلان فيها مفاتيح الأمان. تخزن الأجهزة هذه المفاتيح
مؤقتًا لاستخدامها لاحقًا. بعد اكتمال عمليات الإقران والترابط،
يتبادل الجهازان المعلومات. عند اكتمال الجلسة،
يؤدي الجهاز الذي بدأ طلب الإقران إلى إطلاق القناة التي
ربطته بالجهاز القابل للاكتشاف. ومع ذلك، يظل الجهازان مرتبطين ببعضهما البعض، لذلك
يمكنهما إعادة الاتصال تلقائيًا أثناء أي جلسة مستقبلية طالما أنهما في نطاق
بعضهما البعض ولم تتم إزالة الرابط.
يتطلّب استخدام واجهات برمجة التطبيقات Bluetooth API
الإعلان عن عدة أذونات
في ملف البيان. بعد حصول تطبيقك على إذن لاستخدام البلوتوث، سيحتاج التطبيق إلى
الوصول إلى
BluetoothAdapter
و
تحديد ما إذا كانت تقنية البلوتوث متاحة على الجهاز.
إذا كان البلوتوث متاحًا، عليك اتّباع ثلاث خطوات لإجراء الاتصال:
تستخدم بعض الأجهزة ملفًا شخصيًا لميزة "بلوتوث" يُعلن عن البيانات التي يوفّرها.
الفئات الرئيسية والواجهات
تتوفّر جميع واجهات برمجة تطبيقات Bluetooth في حزمة
android.bluetooth
.
في ما يلي الفئات والواجهات التي تحتاجها لإنشاء
اتصالات بلوتوث:
BluetoothAdapter
- يمثِّل محوِّل البلوتوث المحلي (راديو البلوتوث). جهاز
BluetoothAdapter
هو نقطة الدخول إلى كل تفاعلات البلوتوث. باستخدام
هذا، يمكنك اكتشاف أجهزة بلوتوث أخرى والاستعلام عن قائمة بالأجهزة
(الإقران) وإنشاء مثيل لـ BluetoothDevice
باستخدام عنوان MAC معروف، وإنشاء
BluetoothServerSocket
للاستماع إلى الاتصالات من الأجهزة الأخرى.
BluetoothDevice
- يمثل جهازًا يعمل عن بُعد يتضمّن بلوتوث. استخدِم هذا الرابط لطلب الاتصال بجهاز بعيد من خلال
BluetoothSocket
أو لطلب معلومات عن الجهاز، مثل اسمه وعنوانه وفئته وحالة الربط.
BluetoothSocket
- تمثل واجهة مقبس بلوتوث (على غرار TCP
Socket
). وهي نقطة الاتصال التي
تسمح للتطبيق بتبادل البيانات مع جهاز بلوتوث آخر باستخدام
InputStream
و
OutputStream
.
BluetoothServerSocket
- يمثل مقبس خادم مفتوح يتلقى الطلبات الواردة (على غرار
بروتوكول TCP
ServerSocket
). لتوصيل جهازين، يجب أن يفتح أحد الأجهزة مقبس خادم بهذه الفئة. عندما يجري جهاز بعيد بلوتوث طلب اتصال بهذا
الجهاز، يقبل الجهاز الاتصال ثم يعرض
BluetoothSocket
متصلاً.
BluetoothClass
- يصف هذا الإعداد الخصائص العامة لجهاز البلوتوث وإمكاناته.
هذه مجموعة للقراءة فقط من الخصائص التي تحدد فئات الجهاز وخدماته. على الرغم من أنّ هذه المعلومات تقدّم تلميحًا مفيدًا في ما يتعلّق بنوع الجهاز، فإنّ سمات هذه الفئة لا تصف بالضرورة جميع ملفات البلوتوث وخدماتها التي يتيحها الجهاز.
BluetoothProfile
- واجهة تمثّل ملفًا شخصيًا بلوتوث. الملف الشخصي للبلوتوث هو عبارة عن مواصفات واجهة لاسلكية للاتصال عبر البلوتوث بين الأجهزة. ومن الأمثلة على ذلك الملف الشخصي لتطبيق Hands Free. لمزيد من مناقشة الملفات الشخصية، يمكنك الاطّلاع على الملفات الشخصية لميزة البلوتوث.
BluetoothHeadset
- يتيح هذا الخيار استخدام سماعات الرأس التي تعمل بالبلوتوث لاستخدامها مع الهواتف الجوّالة. ويتضمّن ذلك الملف الشخصي لسماعة الرأس التي تعمل بالبلوتوث والملف الشخصي لسماعة بدون لمس الجهاز (الإصدار 1.5).
BluetoothA2dp
- يحدد هذا الإعداد كيفية بث الصوت العالي الجودة من جهاز إلى آخر
عبر اتصال بلوتوث باستخدام الملف الشخصي لتوزيع الصوت المتقدم (A2DP).
BluetoothHealth
- يمثِّل خادمًا وكيلاً لملف تعريف الجهاز المتعلّق بالصحة يتحكّم في خدمة البلوتوث.
BluetoothHealthCallback
- فئة مجردة تستخدمها لتنفيذ
BluetoothHealth
من عمليات معاودة الاتصال. يجب
توسيع هذه الفئة وتنفيذ طرق معاودة الاتصال لتلقّي آخر الأخبار
حول التغييرات في حالة تسجيل التطبيق وحالة قناة
البلوتوث.
BluetoothHealthAppConfiguration
- يمثل إعداد التطبيق الذي يسجله التطبيق التابع لجهة خارجية في Bluetooth Health
للاتصال بجهاز بلوتوث عن بُعد.
BluetoothProfile.ServiceListener
- واجهة ترسل إشعارات إلى عملاء الاتصال البيني للعمليات (IPC) في
BluetoothProfile
عند اتصالهم بالخدمة الداخلية التي تشغِّل ملفًا شخصيًا أو غير متصلين بها.
يخضع كل من المحتوى وعيّنات التعليمات البرمجية في هذه الصفحة للتراخيص الموضحّة في ترخيص استخدام المحتوى. إنّ Java وOpenJDK هما علامتان تجاريتان مسجَّلتان لشركة Oracle و/أو الشركات التابعة لها.
تاريخ التعديل الأخير: 2025-07-26 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","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-26 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],null,["# Bluetooth overview\n\nThe Android platform includes support for the Bluetooth network stack, which\nallows a device to wirelessly exchange data with other Bluetooth devices. The\napp framework provides access to the Bluetooth functionality through Bluetooth\nAPIs. These APIs let apps connect to other Bluetooth devices, enabling\npoint-to-point and multipoint wireless features.\n\nUsing the Bluetooth APIs, an app can perform the following:\n\n- Scan for other Bluetooth devices.\n- Query the local Bluetooth adapter for paired Bluetooth devices.\n- Establish RFCOMM channels.\n- Connect to other devices through service discovery.\n- Transfer data to and from other devices.\n- Manage multiple connections.\n\nThis topic focuses on *Classic Bluetooth* . Classic Bluetooth is the right choice\nfor more battery-intensive operations, which include streaming and communicating\nbetween devices. For Bluetooth devices with low power requirements, consider\nusing [Bluetooth Low Energy](/develop/connectivity/bluetooth/ble-overview)\nconnections.\n\nThis documentation describes different Bluetooth\n[profiles](/develop/connectivity/bluetooth/profiles) and explains how to\nuse the Bluetooth APIs to accomplish the four major tasks necessary to\ncommunicate using Bluetooth:\n\n- Setting up Bluetooth.\n- Finding devices that are either paired or available in the local area.\n- Connecting devices.\n- Transferring data between devices.\n\nFor a demonstration of using the Bluetooth APIs, see the [Bluetooth Chat sample\napp](https://github.com/android/connectivity-samples/tree/master/BluetoothChat).\n\nThe basics\n----------\n\nFor Bluetooth-enabled devices to transmit data between each other, they must\nfirst form a channel of communication using a pairing process. One device, a\ndiscoverable device, makes itself available for incoming connection requests.\nAnother device finds the discoverable device using a service discovery process.\nAfter the discoverable device accepts the pairing request, the two devices\ncomplete a bonding process in which they exchange security keys. The devices\ncache these keys for later use. After the pairing and bonding processes are\ncomplete, the two devices exchange information. When the session is complete,\nthe device that initiated the pairing request releases the channel that had\nlinked it to the discoverable device. The two devices remain bonded, however, so\nthey can reconnect automatically during a future session as long as they're in\nrange of each other and neither device has removed the bond.\n\nUse of the Bluetooth APIs requires\n[declaring several permissions](/develop/connectivity/bluetooth/bt-permissions#declare)\nin your manifest file. Once your app has permission to use Bluetooth, your app\nneeds to access the\n[`BluetoothAdapter`](/reference/android/bluetooth/BluetoothAdapter) and\n[determine if Bluetooth is available on the device](/develop/connectivity/bluetooth/setup).\nIf Bluetooth is available, there are three steps to make a connection:\n\n- [Find nearby Bluetooth\n devices](/develop/connectivity/bluetooth/find-bluetooth-devices), either devices that are already paired or new ones.\n- [Connect to a Bluetooth\n device](/develop/connectivity/bluetooth/connect-bluetooth-devices).\n- [Transfer data with the connected\n device](/develop/connectivity/bluetooth/transfer-data).\n\nCertain devices use a specific [Bluetooth\nprofile](/develop/connectivity/bluetooth/profiles) that declares the data\nit provides.\n\nKey classes and interfaces\n--------------------------\n\nAll of the Bluetooth APIs are available in the\n[`android.bluetooth`](/reference/android/bluetooth/package-summary) package.\nThe following are the classes and interfaces you need in order to create\nBluetooth connections:\n\n[`BluetoothAdapter`](/reference/android/bluetooth/BluetoothAdapter)\n: Represents the local Bluetooth adapter (Bluetooth radio). The\n `BluetoothAdapter` is the entry-point for all Bluetooth interaction. Using\n this, you can discover other Bluetooth devices, query a list of bonded\n (paired) devices, instantiate a\n `BluetoothDevice` using a known MAC address, and create a\n `BluetoothServerSocket` to listen for communications from other devices.\n\n[`BluetoothDevice`](/reference/android/bluetooth/BluetoothDevice)\n: Represents a remote Bluetooth device. Use this to request a connection with a\n remote device through a `BluetoothSocket` or query information about the\n device such as its name, address, class, and bonding state.\n\n[`BluetoothSocket`](/reference/android/bluetooth/BluetoothSocket)\n: Represents the interface for a Bluetooth socket (similar to a TCP\n [`Socket`](/reference/java/net/Socket)). This is the connection point that\n allows an app to exchange data with another Bluetooth device using\n [`InputStream`](/reference/java/io/InputStream) and\n [`OutputStream`](/reference/java/io/OutputStream).\n\n[`BluetoothServerSocket`](/reference/android/bluetooth/BluetoothServerSocket)\n: Represents an open server socket that listens for incoming requests (similar\n to a TCP [`ServerSocket`](/reference/java/net/ServerSocket)). In order to\n connect two devices, one device must open a server socket with this\n class. When a remote Bluetooth device makes a connection request to this\n device, the device accepts the connection and then returns a connected\n `BluetoothSocket`.\n\n[`BluetoothClass`](/reference/android/bluetooth/BluetoothClass)\n: Describes the general characteristics and capabilities of a Bluetooth device.\n This is a read-only set of properties that defines the device's classes and\n services. Although this information provides a useful hint regarding a\n device's type, the attributes of this class don't necessarily describe all\n Bluetooth profiles and services that the device supports.\n\n[`BluetoothProfile`](/reference/android/bluetooth/BluetoothProfile)\n: An interface that represents a Bluetooth profile. A Bluetooth profile is a\n wireless interface specification for Bluetooth-based communication between\n devices. An example is the Hands-Free profile. For more discussion of\n profiles, see [Bluetooth profiles](/develop/connectivity/bluetooth/profiles).\n\n[`BluetoothHeadset`](/reference/android/bluetooth/BluetoothHeadset)\n: Provides support for Bluetooth headsets to be used with mobile phones. This\n includes both the Bluetooth Headset profile and the Hands-Free (v1.5) profile.\n\n[`BluetoothA2dp`](/reference/android/bluetooth/BluetoothA2dp)\n: Defines how high-quality audio can be streamed from one device to another over\n a Bluetooth connection using the Advanced Audio Distribution Profile (A2DP).\n\n[`BluetoothHealth`](/reference/android/bluetooth/BluetoothHealth)\n: Represents a Health Device Profile proxy that controls the Bluetooth service.\n\n[`BluetoothHealthCallback`](/reference/android/bluetooth/BluetoothHealthCallback)\n: An abstract class that you use to implement `BluetoothHealth` callbacks. You\n must extend this class and implement the callback methods to receive updates\n about changes in the app's registration state and Bluetooth channel\n state.\n\n[`BluetoothHealthAppConfiguration`](/reference/android/bluetooth/BluetoothHealthAppConfiguration)\n: Represents an app configuration that the Bluetooth Health third-party\n app registers to communicate with a remote Bluetooth health device.\n\n[`BluetoothProfile.ServiceListener`](/reference/android/bluetooth/BluetoothProfile.ServiceListener)\n: An interface that notifies `BluetoothProfile` interprocess communication (IPC)\n clients when they have been connected to or disconnected from the internal\n service that runs a particular profile."]]