با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
API بلوتوث شامل پشتیبانی از کار با پروفایل های بلوتوث است. نمایه بلوتوث یک مشخصات رابط بیسیم برای ارتباط مبتنی بر بلوتوث بین دستگاهها، مانند نمایه هندزفری است. برای اتصال دستگاه تلفن همراه به هدست بی سیم، هر دو دستگاه باید از نمایه هندزفری پشتیبانی کنند.
بلوتوث API پیاده سازی هایی را برای پروفایل های بلوتوث زیر فراهم می کند:
هدست . نمایه Headset از هدست های بلوتوث برای استفاده در تلفن های همراه پشتیبانی می کند. اندروید کلاس BluetoothHeadset را ارائه میکند که یک پروکسی برای کنترل سرویس هدست بلوتوث است. این شامل هر دو پروفایل هدست بلوتوث و هندزفری (نسخه 1.5) می شود. کلاس BluetoothHeadset شامل پشتیبانی از دستورات AT است. برای اطلاعات بیشتر در مورد این موضوع، دستورات AT خاص فروشنده را ببینید.
A2DP . نمایه Advanced Audio Distribution Profile (A2DP) تعریف می کند که چگونه می توان صدای با کیفیت بالا را از یک دستگاه به دستگاه دیگر از طریق اتصال بلوتوث پخش کرد. اندروید کلاس BluetoothA2dp را ارائه می کند که یک پروکسی برای کنترل سرویس بلوتوث A2DP است.
دستگاه بهداشتی . اندروید از نمایه دستگاه سلامت بلوتوث (HDP) پشتیبانی می کند. این به شما امکان میدهد برنامههایی بسازید که از بلوتوث برای برقراری ارتباط با دستگاههای بهداشتی که از بلوتوث پشتیبانی میکنند، مانند نمایشگرهای ضربان قلب، سنجهای خون، دماسنج، ترازو و غیره استفاده کنید. برای فهرستی از دستگاههای پشتیبانیشده و کدهای تخصصی دادههای دستگاه مربوطه، به بخش تخصصی دادههای دستگاه HDP HDP مراجعه کنید. این مقادیر همچنین در مشخصات ISO/IEEE 11073-20601 [7] به عنوان MDC_DEV_SPEC_PROFILE_* در ضمیمه کدهای نامگذاری ارجاع شده اند. برای اطلاعات بیشتر در مورد HDP، نمایه دستگاه بهداشتی را ببینید.
در اینجا مراحل اولیه کار با نمایه وجود دارد:
همانطور که در تنظیمات بلوتوث توضیح داده شده است، آداپتور پیش فرض را دریافت کنید.
از getProfileProxy() برای ایجاد ارتباط با شیء پروکسی پروفایل مرتبط با پروفایل استفاده کنید. در مثال زیر، شیء پروکسی نمایه نمونهای از BluetoothHeadset است.
هنگامی که شیء پروکسی پروفایل را دارید، از آن برای نظارت بر وضعیت اتصال و انجام سایر عملیات مرتبط با آن نمایه استفاده کنید.
قطعه کد زیر نحوه اتصال به یک شی پراکسی BluetoothHeadset را نشان می دهد تا بتوانید نمایه Headset را کنترل کنید:
کاتلین
varbluetoothHeadset:BluetoothHeadset? =null// Get the default adaptervalbluetoothAdapter:BluetoothAdapter? =BluetoothAdapter.getDefaultAdapter()privatevalprofileListener=object:BluetoothProfile.ServiceListener{overridefunonServiceConnected(profile:Int,proxy:BluetoothProfile){if(profile==BluetoothProfile.HEADSET){bluetoothHeadset=proxyasBluetoothHeadset}}overridefunonServiceDisconnected(profile:Int){if(profile==BluetoothProfile.HEADSET){bluetoothHeadset=null}}}// Establish connection to the proxy.bluetoothAdapter?.getProfileProxy(context,profileListener,BluetoothProfile.HEADSET)// ... call functions on bluetoothHeadset// Close proxy connection after use.bluetoothAdapter?.closeProfileProxy(BluetoothProfile.HEADSET,bluetoothHeadset)
جاوا
BluetoothHeadsetbluetoothHeadset;// Get the default adapterBluetoothAdapterbluetoothAdapter=BluetoothAdapter.getDefaultAdapter();privateBluetoothProfile.ServiceListenerprofileListener=newBluetoothProfile.ServiceListener(){publicvoidonServiceConnected(intprofile,BluetoothProfileproxy){if(profile==BluetoothProfile.HEADSET){bluetoothHeadset=(BluetoothHeadset)proxy;}}publicvoidonServiceDisconnected(intprofile){if(profile==BluetoothProfile.HEADSET){bluetoothHeadset=null;}}};// Establish connection to the proxy.bluetoothAdapter.getProfileProxy(context,profileListener,BluetoothProfile.HEADSET);// ... call functions on bluetoothHeadset// Close proxy connection after use.bluetoothAdapter.closeProfileProxy(bluetoothHeadset);
دستورات AT خاص فروشنده
برنامهها میتوانند برای دریافت پخشهای سیستمی دستورات AT از پیش تعریفشده خاص فروشنده که توسط هدستها ارسال میشوند (مانند دستور Plantronics +XEVENT) ثبت نام کنند. به عنوان مثال، یک برنامه میتواند پخشهایی را دریافت کند که میزان باتری دستگاه متصل را نشان میدهد و میتواند کاربر را مطلع کند یا اقدامات دیگری را در صورت نیاز انجام دهد. یک گیرنده پخش برای هدف ACTION_VENDOR_SPECIFIC_HEADSET_EVENT ایجاد کنید تا دستورات AT خاص فروشنده را برای هدست مدیریت کند.
هنگام استفاده از Bluetooth Health API، درک این مفاهیم کلیدی HDP مفید است:
منبع
یک وسیله بهداشتی، مانند ترازو، گلوکز متر یا دماسنج که داده های پزشکی را به یک دستگاه هوشمند مانند تلفن یا تبلت اندرویدی منتقل می کند.
غرق شدن
دستگاه هوشمندی که داده های پزشکی را دریافت می کند. در یک برنامه HDP، سینک با یک شیء BluetoothHealthAppConfiguration نشان داده می شود.
ثبت نام
فرآیندی که برای ثبت سینک برای برقراری ارتباط با یک دستگاه بهداشتی خاص استفاده می شود.
اتصال
فرآیندی که برای باز کردن یک کانال بین یک دستگاه سلامت (منبع) و یک دستگاه هوشمند (سینک) استفاده می شود.
یک برنامه HDP ایجاد کنید
در اینجا مراحل اساسی مربوط به ایجاد یک برنامه HDP آمده است:
مرجعی به شیء پروکسی BluetoothHealth دریافت کنید. همانند هدستهای معمولی و دستگاههای نمایه A2DP، باید getProfileProxy() با یک BluetoothProfile.ServiceListener و نوع پروفایل HEALTH برای برقراری ارتباط با شی پراکسی پروفایل فراخوانی کنید.
یک BluetoothHealthCallback ایجاد کنید و یک پیکربندی برنامه ( BluetoothHealthAppConfiguration ) را ثبت کنید که به عنوان یک سینک سلامت عمل می کند.
اتصال به یک دستگاه بهداشتی را ایجاد کنید.
هنگامی که با موفقیت به یک دستگاه سلامت متصل شد، با استفاده از توصیفگر فایل، دستگاه سلامت را بخوانید و بنویسید. داده های دریافتی باید با استفاده از یک مدیر سلامت که مشخصات IEEE 11073 را پیاده سازی می کند، تفسیر شود.
پس از اتمام، کانال سلامت را ببندید و برنامه را لغو ثبت کنید. کانال همچنین در صورت عدم فعالیت طولانی مدت بسته می شود.
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و OpenJDK علامتهای تجاری یا علامتهای تجاری ثبتشده Oracle و/یا وابستههای آن هستند.
تاریخ آخرین بهروزرسانی 2025-07-29 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-07-29 بهوقت ساعت هماهنگ جهانی."],[],[],null,["# Bluetooth profiles\n\nThe Bluetooth API includes support for working with Bluetooth profiles. A\nBluetooth profile is a wireless interface specification for Bluetooth-based\ncommunication between devices, such as the Hands-Free profile. For a mobile\ndevice to connect to a wireless headset, both devices must support the\nHands-Free profile.\n\nThe Bluetooth API provides implementations for the following Bluetooth\nprofiles:\n\n- **Headset** . The Headset profile provides support for Bluetooth headsets to be used with mobile phones. Android provides the [`BluetoothHeadset`](/reference/android/bluetooth/BluetoothHeadset) class, which is a proxy for controlling the Bluetooth Headset Service. This includes both Bluetooth Headset and Hands-Free (v1.5) profiles. The `BluetoothHeadset` class includes support for AT commands. For more on this topic, see [Vendor-specific AT commands](#at-commands).\n- **A2DP** . The Advanced Audio Distribution Profile (A2DP) profile defines how high-quality audio can be streamed from one device to another over a Bluetooth connection. Android provides the [`BluetoothA2dp`](/reference/android/bluetooth/BluetoothA2dp) class, which is a proxy for controlling the Bluetooth A2DP Service.\n- **Health Device** . Android provides support for the Bluetooth Health Device Profile (HDP). This lets you create apps that use Bluetooth to communicate with health devices that support Bluetooth, such as heart-rate monitors, blood meters, thermometers, scales, and so on. For a list of supported devices and their corresponding device data specialization codes, see [Bluetooth's HDP\n Device Data\n Specializations](https://www.bluetooth.com/specifications/assigned-numbers/health-device-profile). These values are also referenced in the ISO/IEEE 11073-20601 \\[7\\] specification as `MDC_DEV_SPEC_PROFILE_*` in the Nomenclature Codes Annex. For more information about HDP, see [Health Device Profile](#health-profile).\n\nHere are the basic steps for working with a profile:\n\n1. Get the default adapter, as described in [Bluetooth setup](/develop/connectivity/bluetooth/setup).\n2. Set up a [`BluetoothProfile.ServiceListener`](/reference/android/bluetooth/BluetoothProfile.ServiceListener). This listener notifies [`BluetoothProfile`](/reference/android/bluetooth/BluetoothProfile) clients when they have been connected to or disconnected from the service.\n3. Use [`getProfileProxy()`](/reference/android/bluetooth/BluetoothAdapter#getProfileProxy(android.content.Context,%20android.bluetooth.BluetoothProfile.ServiceListener,%20int)) to establish a connection to the profile proxy object associated with the profile. In the following example, the profile proxy object is an instance of `BluetoothHeadset`.\n4. In [`onServiceConnected()`](/reference/android/bluetooth/BluetoothProfile.ServiceListener#onServiceConnected(int,%20android.bluetooth.BluetoothProfile)), get a handle to the profile proxy object.\n5. Once you have the profile proxy object, use it to monitor the state of the connection and perform other operations that are relevant to that profile.\n\nThe following code snippet shows how to connect to a `BluetoothHeadset` proxy\nobject so that you can control the Headset profile: \n\n### Kotlin\n\n```kotlin\nvar bluetoothHeadset: BluetoothHeadset? = null\n\n// Get the default adapter\nval bluetoothAdapter: BluetoothAdapter? = BluetoothAdapter.getDefaultAdapter()\n\nprivate val profileListener = object : BluetoothProfile.ServiceListener {\n\n override fun onServiceConnected(profile: Int, proxy: BluetoothProfile) {\n if (profile == BluetoothProfile.HEADSET) {\n bluetoothHeadset = proxy as BluetoothHeadset\n }\n }\n\n override fun onServiceDisconnected(profile: Int) {\n if (profile == BluetoothProfile.HEADSET) {\n bluetoothHeadset = null\n }\n }\n}\n\n// Establish connection to the proxy.\nbluetoothAdapter?.getProfileProxy(context, profileListener, BluetoothProfile.HEADSET)\n\n// ... call functions on bluetoothHeadset\n\n// Close proxy connection after use.\nbluetoothAdapter?.closeProfileProxy(BluetoothProfile.HEADSET, bluetoothHeadset)\n```\n\n### Java\n\n```java\nBluetoothHeadset bluetoothHeadset;\n\n// Get the default adapter\nBluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();\n\nprivate BluetoothProfile.ServiceListener profileListener = new BluetoothProfile.ServiceListener() {\n public void onServiceConnected(int profile, BluetoothProfile proxy) {\n if (profile == BluetoothProfile.HEADSET) {\n bluetoothHeadset = (BluetoothHeadset) proxy;\n }\n }\n public void onServiceDisconnected(int profile) {\n if (profile == BluetoothProfile.HEADSET) {\n bluetoothHeadset = null;\n }\n }\n};\n\n// Establish connection to the proxy.\nbluetoothAdapter.getProfileProxy(context, profileListener, BluetoothProfile.HEADSET);\n\n// ... call functions on bluetoothHeadset\n\n// Close proxy connection after use.\nbluetoothAdapter.closeProfileProxy(bluetoothHeadset);\n```\n\n### Vendor-specific AT commands\n\nApps can register to receive system broadcasts of predefined vendor-specific AT\ncommands sent by headsets (such as a Plantronics +XEVENT command). For example,\nan app could receive broadcasts that indicate a connected device's battery level\nand could notify the user or take other action as needed. Create a broadcast\nreceiver for the\n[`ACTION_VENDOR_SPECIFIC_HEADSET_EVENT`](/reference/android/bluetooth/BluetoothHeadset#ACTION_VENDOR_SPECIFIC_HEADSET_EVENT)\nintent to handle vendor-specific AT commands for the headset.\n\nHealth Device Profile\n---------------------\n\nAndroid supports the Bluetooth Health Device Profile (HDP). The Bluetooth Health\nAPI includes the classes\n[`BluetoothHealth`](/reference/android/bluetooth/BluetoothHealth),\n[`BluetoothHealthCallback`](/reference/android/bluetooth/BluetoothHealthCallback),\nand\n[`BluetoothHealthAppConfiguration`](/reference/android/bluetooth/BluetoothHealthAppConfiguration),\nwhich are described in [Key classes and\ninterfaces](/develop/connectivity/bluetooth#key-classes).\n| **Caution:** The Health Device Profile (HDP) and MCAP protocols are no longer used. New apps should use Bluetooth Low Energy based solutions such as [`BluetoothGatt`](/reference/android/bluetooth/BluetoothGatt), [`BluetoothAdapter.listenUsingL2capChannel()`](/reference/android/bluetooth/BluetoothAdapter#listenUsingL2capChannel()), or [`BluetoothDevice#createL2capChannel(int)`](/reference/android/bluetooth/BluetoothDevice#createL2capChannel(int)).\n\nWhen using the Bluetooth Health API, it's helpful to understand these key HDP\nconcepts:\n\nSource\n: A health device, such as a weight scale, glucose meter, or thermometer, which\n transmits medical data to a smart device, such as an Android phone or tablet.\n\nSink\n: The smart device that receives the medical data. In an HDP app, the\n sink is represented by a `BluetoothHealthAppConfiguration` object.\n\nRegistration\n: The process used to register a sink for communicating with a particular health\n device.\n\nConnection\n: The process used to open a channel between a health device (source) and a\n smart device (sink).\n\n### Create an HDP app\n\nHere are the basic steps involved in creating an HDP app:\n\n1. Get a reference to the `BluetoothHealth` proxy object. As with regular\n headset and A2DP profile devices, you must call `getProfileProxy()` with a\n `BluetoothProfile.ServiceListener` and the\n [`HEALTH`](/reference/android/bluetooth/BluetoothProfile#HEALTH) profile type\n to establish a connection with the profile proxy object.\n\n2. Create a `BluetoothHealthCallback` and register an app configuration\n (`BluetoothHealthAppConfiguration`) that acts as a health sink.\n\n3. Establish a connection to a health device.\n\n | **Note:** Some devices initiate the connection automatically. It is unnecessary to carry out this step for those devices.\n4. When connected successfully to a health device, read and write to the health\n device using the file descriptor. The received data needs to be interpreted\n using a health manager, which implements the [IEEE 11073\n specifications](https://standards.ieee.org/standard/11073-10207-2017.html).\n\n5. When done, close the health channel and unregister the app. The channel also\n closes when there is extended inactivity."]]