بلوتوث منخفض الطاقة
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
يوفّر Android نظامًا أساسيًا مدمجًا متوافقًا مع تقنية Bluetooth Low Energy (BLE) في الدور المركزي ويوفر واجهات برمجة تطبيقات يمكن للتطبيقات استخدامها لاكتشاف الأجهزة وطلب الخدمات ونقل المعلومات.
تشمل حالات الاستخدام الشائعة ما يلي:
- نقل كميات صغيرة من البيانات بين الأجهزة القريبة
- التفاعل مع أدوات استشعار التقارب لتقديم تجربة مخصّصة للمستخدمين استنادًا
إلى موقعهم الجغرافي الحالي
على عكس البلوتوث الكلاسيكي،
تم تصميم تقنية BLE لاستهلاك طاقة أقل بكثير. يتيح ذلك للتطبيقات
التواصل مع أجهزة BLE التي تتطلب طاقة أكثر صرامة، مثل
أجهزة استشعار التقارب وأجهزة مراقبة معدل ضربات القلب وأجهزة اللياقة البدنية.
تحذير: عندما يقرِن المستخدم جهازه بجهاز آخر باستخدام تقنية BLE، يمكن لجميع التطبيقات على جهاز المستخدم الوصول إلى البيانات التي يتم تبادلها بين الجهازَين.
لهذا السبب، إذا كان تطبيقك يجمع بيانات حسّاسة، عليك تنفيذ
إجراءات أمان على مستوى التطبيق لحماية خصوصية هذه البيانات.
الأساسيات
لكي تتمكن الأجهزة المزوّدة بتقنية BLE من نقل البيانات مع بعضها، يجب أولاً
إنشاء قناة اتصال. يتطلّب استخدام واجهات برمجة تطبيقات Bluetooth LE
الإفصاح عن العديد من الأذونات
في ملف البيان. بعد أن يحصل تطبيقك على إذن استخدام البلوتوث، عليه
الوصول إلى BluetoothAdapter
وتحديد ما إذا كان البلوتوث متاحًا على الجهاز
. وإذا كان البلوتوث متاحًا، سيبدأ الجهاز في
البحث عن أجهزة BLE المجاورة.
بعد العثور على جهاز، يتم اكتشاف إمكانات جهاز BLE من خلال
الاتصال بخادم GATT على جهاز BLE.
بعد إجراء عملية الربط،
يمكن نقل البيانات باستخدام الجهاز المرتبط
استنادًا إلى الخدمات والسمات المتاحة.
المصطلحات والمفاهيم الرئيسية
في ما يلي ملخّص لمصطلحات ومفاهيم BLE:
- الملف الشخصي للسمات العامة (GATT)
- ملف GATT الشخصي هو مواصفة عامة لإرسال وتلقّي قطعة data قصيرة تُعرف باسم "السمات" عبر رابط BLE. تستند جميع ملفات تطبيق BLE
الحالية إلى بروتوكول GATT. راجِع نموذج Android BluetoothLeGatt
على GitHub للاطّلاع على مزيد من المعلومات.
- الملفات الشخصية
- تحدِّد Bluetooth SIG العديد من
الملفات الشخصية
لأجهزة BLE. الملف الشخصي هو مواصفات لطريقة عمل الجهاز في
تطبيق معيّن. يُرجى العِلم أنّه يمكن للجهاز تنفيذ أكثر من
ملف شخصي واحد. على سبيل المثال، يمكن أن يحتوي الجهاز على جهاز مراقبة معدل ضربات القلب وجهاز رصد
مستوى البطارية.
- بروتوكول السمة (ATT)
- تم إنشاء بروتوكول GATT استنادًا إلى بروتوكول السمات (ATT). ويُشار إلى ذلك أيضًا باسم
GATT/ATT. تم تحسين إطار عمل ATT للعمل على الأجهزة التي تتضمّن تقنية البلوتوث منخفضة الطاقة. وتحقيقاً لهذه الغاية، يستخدم التنسيق
أقل عدد ممكن من البايتات. يتم تعريف كل سمة بشكل فريد باستخدام معرّف عالمي
فريد (UUID)، وهو تنسيق موحّد مكوّن من 128 بت لسمة
معرّف تُستخدَم لتحديد المعلومات بشكل فريد. يتم تنسيق السمات التي تم نقلها من خلال سياسة "شفافية تتبُّع التطبيقات"
كـ خصائص وخدمات.
- السمة
- تحتوي السمة على قيمة واحدة وعدد متغير من الأوصاف التي تصف قيمة
السمة. يمكن اعتبار السمة نوعًا،
يشبه الفئة.
- الوصف
- وسائل الوصف هي سمات محدّدة تصف قيمة سمة. على سبيل المثال، قد يحدّد المعرّف وصفًا مفهومًا للمستخدمين أو نطاقاً مقبولاً لقيمة السمة أو وحدة قياس خاصة بقيمة السمة.
- الخدمة
- الخدمة هي مجموعة من الخصائص. على سبيل المثال، يمكن أن يكون لديك
خدمة باسم "جهاز مراقبة معدل ضربات القلب" تتضمّن خصائص مثل
"قياس معدل ضربات القلب". يمكنك العثور على قائمة بالملفات الشخصية
والخدمات الحالية المستندة إلى GATT على bluetooth.org.
الأدوار والمسؤوليات
عندما يتفاعل جهاز مع جهاز BLE، يتم хувين الأدوار والمسؤوليات بطريقتَين مختلفتَين:
الأجهزة المركزية مقابل الأجهزة الملحقة: ينطبق ذلك على اتصال BLE نفسه، حيث يبحث العميل المتصل في الدور المركزي عن إعلان، ويُرسِل العميل المتصل في الدور الثانوي إعلانًا. لا يمكن لجهازَين يتيحان فقط دور الجهاز الملحق
التواصل مع بعضهما، ولا يمكن لجهازَين يتيحان فقط دور الجهاز المركزي
التواصل مع بعضهما.
خادم GATT مقارنةً ببرنامج GATT العميل يحدِّد هذا الإعداد كيفية تواصل الجهازَين معًا بعد بدء الاتصال. يرسل الجهاز الذي يلعب دور العميل طلبات للحصول على البيانات، وينفِّذها الجهاز الذي يلعب دور الخادم.
لفهم الفرق بين أدوار الجهاز المركزي والجهاز الطرفي وتلك الخاصة بالخادم والعميل، ننصحك بالاطّلاع على مثال يتضمن هاتف Android وجهاز تتبُّع نشاط مزوّدًا بتقنية BLE يُرسِل بيانات أجهزة الاستشعار إلى الهاتف.
يبحث الهاتف، وهو الجهاز المركزي، بشكل نشط عن أجهزة BLE. يُعلِن جهاز التتبُّع
للنشاط، وهو الجهاز الجانبي، عن نفسه وينتظر تلقّي طلب
الاتصال.
بعد إنشاء اتصال بين الهاتف ومتتبع النشاط،
يبدأان في نقل بيانات GATT الوصفية إلى بعضهما البعض. في هذه الحالة، يُرسِل التطبيق الذي يعمل
على الهاتف طلبات للحصول على البيانات، وبالتالي يعمل كـ عميل GATT. ينفِّذ جهاز التتبُّع
هذه الطلبات، لذا فهو يعمل بمثابة خادم GATT.
قد يتضمن تصميم بديل للتطبيق الهاتف الذي يلعب دور خادم GATT
بدلاً من ذلك. يمكنك الاطّلاع على
BluetoothGattServer
لمزيد من المعلومات.
يخضع كل من المحتوى وعيّنات التعليمات البرمجية في هذه الصفحة للتراخيص الموضحّة في ترخيص استخدام المحتوى. إنّ 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,["# Bluetooth Low Energy\n\nAndroid provides built-in platform support for Bluetooth Low Energy (BLE) in the\ncentral role and provides APIs that apps can use to discover devices, query for\nservices, and transmit information.\n\nCommon use cases include the following:\n\n- Transferring small amounts of data between nearby devices.\n- Interacting with proximity sensors to give users a customized experience based on their current location.\n\nIn contrast to [classic Bluetooth](/develop/connectivity/bluetooth),\nBLE is designed for significantly lower power consumption. This allows apps to\ncommunicate with BLE devices that have stricter power requirements, such as\nproximity sensors, heart rate monitors, and fitness devices. \n\n**Caution:** When a user pairs their device with another device\nusing BLE, the data that's communicated between the two devices is\naccessible to **all** apps on the user's device.\n\n\nFor this reason, if your app captures sensitive data, you should implement\napp-layer security to protect the privacy of that data.\n\nThe basics\n----------\n\nFor BLE-enabled devices to transmit data between each other, they must first\nform a channel of communication. Use of the Bluetooth LE APIs requires you to\n[declare several permissions](/develop/connectivity/bluetooth/bt-permissions)\nin your manifest file. Once your app has permission to use Bluetooth, your app\nneeds to access the `BluetoothAdapter` and\n[determine if Bluetooth is available on the device](/develop/connectivity/bluetooth/setup)\nIf Bluetooth is available, the device will\n[scan for nearby BLE devices](/develop/connectivity/bluetooth/ble/find-ble-devices).\nOnce a device is found, the capabilities of the BLE device are discovered by\n[connecting to the GATT server on the BLE device](/develop/connectivity/bluetooth/ble/connect-gatt-server).\nOnce a connection is made,\n[data can be transferred with the connected device](/develop/connectivity/bluetooth/ble/transfer-ble-data)\nbased on the available services and characteristics.\n\nKey terms and concepts\n----------------------\n\nThe following is a summary of key BLE terms and concepts:\n\n-\n\n **Generic Attribute Profile (GATT)**\n : The GATT profile is a general specification for sending and receiving short\n pieces of data known as \"attributes\" over a BLE link. All current BLE\n application profiles are based on GATT. Review the [Android BluetoothLeGatt\n sample](https://github.com/android/platform-samples/tree/main/samples/connectivity/bluetooth/ble/src/main/java/com/example/platform/connectivity/bluetooth/ble)\n on GitHub to learn more.\n-\n\n **Profiles**\n : The **Bluetooth SIG** defines many\n [profiles](https://www.bluetooth.org/en-us/specification/adopted-specifications)\n for BLE devices. A profile is a specification for how a device works in a\n particular application. Note that a device can implement more than one\n profile. For example, a device could contain a heart rate monitor and a\n battery level detector.\n-\n\n **Attribute Protocol (ATT)**\n : GATT is built on top of the Attribute Protocol (ATT). This is also referred to\n as GATT/ATT. ATT is optimized to run on BLE devices. To this end, it uses as\n few bytes as possible. Each attribute is uniquely identified by a Universally\n Unique Identifier (UUID), which is a standardized 128-bit format for a string\n ID used to uniquely identify information. The *attributes* transported by ATT\n are formatted as *characteristics* and *services*.\n-\n\n **Characteristic**\n : A characteristic contains a single value and 0-n descriptors that describe the\n characteristic's value. A characteristic can be thought of as a type,\n analogous to a class.\n-\n\n **Descriptor**\n : Descriptors are defined attributes that describe a characteristic value. For\n example, a descriptor might specify a human-readable description, an\n acceptable range for a characteristic's value, or a unit of measure that is\n specific to a characteristic's value.\n-\n\n **Service**\n : A service is a collection of characteristics. For example, you could have a\n service called \"Heart Rate Monitor\" that includes characteristics such as\n \"heart rate measurement.\" You can find a list of existing GATT-based profiles\n and services on [bluetooth.org](https://www.bluetooth.org/en-us/specification/adopted-specifications).\n\n### Roles and responsibilities\n\nWhen a device interacts with a BLE device, roles and responsibilities are\ndivided in two different ways:\n\n- **Central versus peripheral.** This applies to the BLE connection itself---the\n device in the central role scans, looking for advertisement, and the device in\n the peripheral role advertises. Two devices that only support the peripheral\n role can't talk to each other, and neither can two devices that only support\n the central role.\n\n- **GATT server versus GATT client.** This determines how the two devices talk\n to each other after they've established the connection. The device in the\n client role sends requests for data, and the device in the server role\n fulfills them.\n\nTo understand the distinction between the central-peripheral and server-client\nrole divisions, consider an example where you have an Android phone and a\nBLE-enabled activity tracker that reports sensor data back to the phone.\n\n- The phone---the *central* device---actively scans for BLE devices. The activity\n tracker---the *peripheral* device---advertises and waits to receive a request for\n connection.\n\n- After the phone and the activity tracker have established a connection, they\n start transferring GATT metadata to each other. In this case, the app running\n on the phone sends requests for data, so it acts as the *GATT client* . The\n activity tracker fulfills those requests, so it acts as the *GATT server*.\n\nAn alternative design of the app might involve the phone playing the GATT server\nrole instead. See\n[`BluetoothGattServer`](/reference/android/bluetooth/BluetoothGattServer) for\nmore information."]]