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