קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
ממשקי ה-API של שכבת הנתונים של Wear OS מורכבים מכמה סוגים שונים של לקוחות, שמתאימים לסוגים שונים של נתונים ובתנאי קישוריות שונים.
בדף הזה מוצגים כל סוגי הלקוחות, ויש בו טבלה שמציגה השוואה בין היכולות של הלקוחות השונים. בעזרת המידע הזה תוכלו לבחור את קבוצת סוגי הלקוחות שהכי מתאימה לאפליקציה שלכם.
כל DataItem הוא יחידת מידע שמשודרת ומסונכרנת בכל המכשירים שבקרבת מקום שבבעלות המשתמש. DataItem נשמר באופן קבוע, והמכשיר יכול לקרוא את התוכן שלו עד שמוחקים את פריט הנתונים.
Asset מיועד לעומסי נתונים גדולים יותר, כמו תמונות או קובצי מדיה.
לקוח שליחת הודעות
אובייקט MessageClient יכול לשלוח הודעות והוא מתאים לקריאות לפרוצדורות מרוחקות (RPC), למשל שימוש במכשיר Wear OS כדי לשלוט בגרסה של האפליקציה שמותקנת במכשיר נייד.
הודעות הן פתרון מצוין לבקשות חד-כיווניות באמצעות sendMessage(), או למודל תקשורת של בקשה ותגובה באמצעות sendRequest(). בניגוד ללקוחות נתונים, כדי לשלוח הודעות, לקוחות הודעות צריכים שהצומתים יהיו מחוברים לרשת.
ה-method sendMessage() הוא ניסיון כמיטב יכולתנו להעביר את ההודעה לצומת המרוחק, והוא לא מכיל מנגנון מובנה לניסיון חוזר. אם מכשיר היעד יתנתק לפני שההעברה ברשת תתחיל, השיטה תחזיר את הערך TARGET_NODE_NOT_CONNECTED.
לקוח ערוץ
אובייקט ChannelClient מספק תקשורת מבוססת-סטרימינג בין מכשירים. ערוץ הוא צינור תקשורת דו-כיווני בין שני צמתים, ששימושי בתרחישי שימוש כמו:
העברת קבצים של נתונים בין שני מכשירים מחוברים או יותר כשאין חיבור לאינטרנט. ChannelClient חוסך מקום בדיסק בהשוואה ל-DataClient, שבו נוצרת עותק של הנכסים במכשיר המקומי לפני הסנכרון עם המכשירים המקושרים.
שליחת קובץ גדול מדי לשלוח באמצעות MessageClient.
העברת נתונים בסטרימינג, כמו נתוני קול מהמיקרופון.
אחרי שפותחים ערוץ, אפשר לשלוח ולקבל נתונים בזרם בייט רציף, במקום ביחידות DataItem נפרדות שנדרשות ללקוחות הנתונים.
אתם אחראים לנהל את זרימת הנתונים ולשמור על עקביות הנתונים.
לקוחות ערוצים לא מציעים את אותה רמה של סנכרון נתונים אוטומטי כמו לקוחות נתונים.
השוואה בין לקוחות
בטבלה הבאה מוצגת השוואה בין היכולות של הלקוחות השונים:
Bluetooth מועדף. הנתונים מגובים בענן. אם ה-Bluetooth זמין, הגיבוי מתבצע באופן אסינכררוני.
כן, גם לקריאה וגם לכתיבה
לקוח שליחת הודעות
ללא עקביות וללא ניסיון חוזר
לא
המערכת מעדיפה חיבור Bluetooth, אבל יכולה להשתמש בחיבור Wi-Fi אם זה סוג החיבור היחיד שזמין
לא
Channel client
ללא עקביות (ממוקדת-חיבור)
כן
המערכת מעדיפה חיבור Bluetooth, אבל יכולה להשתמש בחיבור Wi-Fi אם זה סוג החיבור היחיד שזמין
לא
דוגמאות התוכן והקוד שבדף הזה כפופות לרישיונות המפורטים בקטע רישיון לתוכן. Java ו-OpenJDK הם סימנים מסחריים או סימנים מסחריים רשומים של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-08-30 (שעון UTC).
[[["התוכן קל להבנה","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-08-30 (שעון UTC)."],[],[],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 |"]]