تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
تتألف واجهات برمجة التطبيقات الخاصة بطبقة بيانات Wear OS من عدة أنواع مختلفة من البرامج، وهي مفيدة لأنواع مختلفة من البيانات وفي ظروف اتصال مختلفة.
تقدّم هذه الصفحة كل نوع من أنواع العملاء، وتتضمّن جدولاً يقارن بين إمكانات العملاء المختلفين. باستخدام هذه المعلومات، يمكنك اختيار مجموعة أنواع العملاء التي تناسب تطبيقك على أفضل وجه.
كل DataItem هي وحدة معلومات يتم بثها ومزامنتها
على جميع الأجهزة القريبة التي يملكها المستخدم. يتم تخزين DataItem بشكل دائم، ويمكن لجهازك قراءة محتواه إلى أن يتم حذف عنصر البيانات.
يُستخدم Asset مع حمولات البيانات الأكبر حجمًا، مثل الصور أو ملفات الوسائط.
برنامج المراسلة
يمكن لكائن MessageClient إرسال الرسائل، وهو مناسب لعمليات استدعاء الإجراءات عن بُعد (RPC)، مثل استخدام جهاز Wear OS للتحكّم في إصدار تطبيقك المثبَّت على جهاز جوّال.
تُعد الرسائل رائعة للطلبات أحادية الاتجاه باستخدام sendMessage()، أو لنموذج اتصال يتضمّن طلبًا وردًا باستخدام sendRequest(). على عكس برامج بيانات، تحتاج برامج الرسائل إلى أن تكون العُقد متصلة بالشبكة من أجل إرسال الرسائل.
إنّ طريقة sendMessage() هي أفضل جهد يتم بذله للتسليم إلى العقدة البعيدة، ولا تحتوي على أي آلية مدمجة لإعادة المحاولة. إذا تم قطع اتصال الجهاز المستهدف قبل بدء عملية النقل عبر الشبكة، ستعرض الطريقة القيمة TARGET_NODE_NOT_CONNECTED.
عميل القناة
يوفر عنصر ChannelClient اتصالاً موجّهًا نحو البث بين الأجهزة. القناة هي قناة اتصال ثنائية الاتجاه بين عقدتين،
وهي مفيدة في حالات الاستخدام التالية:
نقل ملفات البيانات بين جهازَين أو أكثر من الأجهزة المتصلة عندما لا يتوفّر اتصال بالإنترنت توفّر ChannelClient مساحة على القرص مقارنةً بـ DataClient، التي تنشئ نسخة من مواد العرض على الجهاز المحلي قبل المزامنة مع الأجهزة المتصلة.
إرسال ملف كبير جدًا لا يمكن إرساله باستخدام MessageClient
نقل البيانات التي يتم بثّها، مثل البيانات الصوتية من الميكروفون
بعد فتح قناة، يمكنك إرسال البيانات وتلقّيها في دفق مستمر من البايتات، بدلاً من وحدات DataItem المنفصلة التي تتطلّبها برامج البيانات.
أنت مسؤول عن إدارة تدفّق البيانات والحفاظ على اتساقها.
لا توفّر برامج عملاء القنوات مستوى المزامنة التلقائية نفسه الذي توفّره برامج عملاء البيانات.
مقارنة العملاء
يقارن الجدول التالي بين إمكانات العملاء المختلفين:
يُفضَّل استخدام البلوتوث. يتم الاحتفاظ بنسخة احتياطية من البيانات على السحابة الإلكترونية، وإذا كان Bluetooth متاحًا، يتم إجراء هذه العملية بشكل غير متزامن.
نعم، للقراءة والكتابة
برنامج المراسلة
لا يتم حفظ البيانات ولا تتم إعادة المحاولة
لا
يُفضّل استخدام البلوتوث، ولكن يمكن استخدام شبكة Wi-Fi إذا كان هذا هو نوع الاتصال الوحيد المتاح.
لا
عميل القناة
لا يتم الحفاظ على الحالة (موجّهة الاتصال)
نعم
يُفضّل استخدام البلوتوث، ولكن يمكن استخدام شبكة Wi-Fi إذا كان هذا هو نوع الاتصال الوحيد المتاح.
لا
يخضع كل من المحتوى وعيّنات التعليمات البرمجية في هذه الصفحة للتراخيص الموضحّة في ترخيص استخدام المحتوى. إنّ Java وOpenJDK هما علامتان تجاريتان مسجَّلتان لشركة Oracle و/أو الشركات التابعة لها.
تاريخ التعديل الأخير: 2025-09-04 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","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-09-04 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],null,["The Wear OS data layer APIs consist of several different types of clients, which\nare useful for different types of data and during different connectivity\nconditions.\n\nThis page introduces each client type, and it includes a table that compares the\ncapabilities of the different clients. Using this information, you can select\nthe set of client types that works best for your app.\n\nData client\n\nA [`DataClient`](https://developers.google.com/android/reference/com/google/android/gms/wearable/DataClient) object lets you read or write to a [`DataItem`](https://developers.google.com/android/reference/com/google/android/gms/wearable/DataItem) or\n[`Asset`](https://developers.google.com/android/reference/com/google/android/gms/wearable/Asset):\n\n- Each `DataItem` is a unit of information that's broadcast and synchronized\n across all nearby devices that a user owns. A `DataItem` is stored persistently,\n and your device can read its contents until the data item is deleted.\n\n- An `Asset` is meant for larger data payloads, such as images or media files.\n\nMessage client\n\nA [`MessageClient`](https://developers.google.com/android/reference/com/google/android/gms/wearable/MessageClient) object can send messages and is good for remote procedure\ncalls (RPC), such as using a Wear OS device to control the version of your app\nthat's installed on a handheld device.\n\nMessages are great for one-way requests using `sendMessage()`, or for a\nrequest-and-response communication model using `sendRequest()`. Unlike with data\nclients, message clients need the nodes to be connected to the network in order\nto send messages.\n\nThe `sendMessage()` method is a best effort to deliver to the remote node, and\nit doesn't contain any built-in retry mechanism. If the target device\ndisconnects before the network transfer starts, the method returns\n`TARGET_NODE_NOT_CONNECTED`.\n| **Note:** To help preserve power, consider sending messages only to nearby devices.\n\nChannel client\n\nA [`ChannelClient`](https://developers.google.com/android/reference/com/google/android/gms/wearable/ChannelClient) object provides stream-oriented communication between\ndevices. A *channel* is a bidirectional communication pipe between two nodes,\nwhich is useful for use cases such as the following:\n\n- Transfer data files between two or more connected devices when the internet isn't available. `ChannelClient` saves disk space over `DataClient`, which creates a copy of the assets on the local device before synchronizing with connected devices.\n- Reliably send a file that's too large to send using a `MessageClient`.\n- Transfer streamed data, such as voice data from the microphone.\n\nAfter you open a channel, you can send and receive data in a continuous byte\nstream, rather than the discrete `DataItem` units that data clients require.\n\nYou're responsible for managing the data flow and keeping data consistent.\nChannel clients don't offer the same level of automatic data synchronization\nthat data clients do.\n\nClient comparison\n\nThe following table compares the capabilities of the different clients:\n\n| Client type | Data persistence | Supports data larger than 100 KB? | Network to use | Works offline? |\n|--------------------|--------------------------------------|--------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------|------------------------------|\n| **Data client** | Data is persisted indefinitely | Yes (use [`Asset`](https://developers.google.com/android/reference/com/google/android/gms/wearable/Asset) objects) | Bluetooth preferred. Data is backed up to the cloud; if Bluetooth is available, this backup is done asynchronously | Yes, for both read and write |\n| **Message client** | No persistence and no retry | No | Bluetooth preferred, but can use Wi-Fi if it's the only type of connection available | No |\n| **Channel client** | No persistence (connection-oriented) | Yes | Bluetooth preferred, but can use Wi-Fi if it's the only type of connection available | No |"]]