Mã mẫu Android
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Kho lưu trữ Google Fit trên GitHub có các mã mẫu giải thích cách sử dụng các API Android. Ngoài ra, còn có các đoạn mã cho các tác vụ phổ biến khác trong hướng dẫn cho nhà phát triển.
Đọc dữ liệu từ cảm biến
Mã mẫu GitHub để đăng ký trình nghe để đọc dữ liệu cảm biến thô từ một nguồn dữ liệu.
Ghi dữ liệu vào bộ nhớ Fit
Mã mẫu GitHub để yêu cầu lưu trữ tự động dữ liệu cảm biến bằng cách tạo các gói thuê bao.
Đọc dữ liệu từ Google Fit
Mã mẫu GitHub để đọc dữ liệu từ nhật ký tập thể dục của người dùng.
Xử lý các phiên hoạt động
Mã mẫu GitHub để minh hoạ các phiên: Đóng gói dữ liệu thể dục dưới dạng một phiên hợp lý để thể hiện một bài tập thể dục tổng thể.
Bộ đếm bước
Mã mẫu GitHub để ghi lại các bước và đọc lại.
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-08-31 UTC.
[null,null,["Cập nhật lần gần đây nhất: 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)."]]