ตัวอย่างโค้ดสำหรับ Android
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ที่เก็บ Google Fit ใน GitHub มีตัวอย่างโค้ดที่อธิบายวิธีใช้ Android API นอกจากนี้ยังมีข้อมูลโค้ดสำหรับงานอื่นๆ
ทั่วไปในคู่มือนักพัฒนาซอฟต์แวร์ด้วย
อ่านข้อมูลจากเซ็นเซอร์
ตัวอย่างโค้ด GitHub ในการลงทะเบียน Listener
เพื่ออ่านข้อมูลดิบของเซ็นเซอร์จากแหล่งข้อมูล
บันทึกข้อมูลลงในพื้นที่เก็บข้อมูล Fit
ตัวอย่างโค้ด GitHub เพื่อขอพื้นที่เก็บข้อมูลเซ็นเซอร์อัตโนมัติ
โดยการสร้างการสมัครใช้บริการ
อ่านข้อมูลจาก Google Fit
ตัวอย่างโค้ด GitHub เพื่ออ่านข้อมูลจากประวัติการออกกำลังกายของผู้ใช้
ใช้งานเซสชัน
ตัวอย่างโค้ด GitHub สำหรับสาธิตเซสชัน:
สรุปข้อมูลการออกกำลังกายเป็นเซสชันเชิงตรรกะ
เพื่อแสดงถึงการออกกำลังกายโดยรวม
ตัวนับก้าว
ตัวอย่างโค้ด GitHub เพื่อบันทึกขั้นตอนและอ่านย้อนกลับ
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-31 UTC
[null,null,["อัปเดตล่าสุด 2025-08-31 UTC"],[[["\u003cp\u003eThe Google Fit repository on GitHub provides code samples demonstrating how to use Android APIs for fitness data.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can find code snippets for common tasks like reading sensor data, recording data, working with sessions, and utilizing the step counter, within the Google Fit repository and developer guide.\u003c/p\u003e\n"],["\u003cp\u003eAccess various GitHub code samples to learn about registering sensor listeners, requesting automated data storage, reading fitness history, and implementing sessions in your fitness applications.\u003c/p\u003e\n"]]],[],null,["# Android code samples\n\nThe [Google Fit repo on GitHub](https://github.com/android/fit) has code samples\nexplaining how to use the Android APIs. There are also code snippets for other\ncommon tasks in the [developer guide](/fit/android).\n\n### Read data from sensors\n\n[GitHub code sample to register listeners](https://github.com/android/fit-samples/tree/master/BasicSensorsApiKotlin)\nto read raw sensor data from a data source.\n\n### Record data to Fit storage\n\n[GitHub code sample to request automated storage of sensor data](https://github.com/android/fit-samples/tree/master/BasicRecordingApiKotlin)\nby creating subscriptions.\n\n### Read data from Google Fit\n\n[GitHub code sample to read data from the user's fitness history](https://github.com/android/fit-samples/tree/master/BasicHistoryApiKotlin).\n\n### Work with sessions\n\n[GitHub code sample to demonstrate sessions](https://github.com/android/fit-samples/tree/master/BasicHistorySessionsKotlin):\nEncapsulate fitness data as a logical [session](/fit/android/using-sessions),\nto represent an overall workout.\n\n### Step counter\n\n[GitHub code sample to record steps and read them back](https://github.com/android/fit-samples/tree/master/StepCounterKotlin)."]]