Các API của Google Fit, bao gồm cả API Google Fit REST, sẽ ngừng hoạt động vào năm 2026. Kể từ ngày 1 tháng 5 năm 2024, nhà phát triển không thể đăng ký sử dụng các API này.
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.
API Google Fit dành cho Android là một phần của Dịch vụ Google Play. API Google Fit được hỗ trợ trên Android 4.1 (API cấp 16) trở lên. Khi sử dụng những API này, ứng dụng của bạn có thể làm những việc sau:
Đọc dữ liệu gần như theo thời gian thực và dữ liệu trong quá khứ, bao gồm cả dữ liệu của các thiết bị Bluetooth năng lượng thấp (BLE).
Ghi lại hoạt động.
Liên kết dữ liệu với một phiên hoạt động.
Đặt mục tiêu rèn luyện thể chất.
Đọc dữ liệu cảm biến
Nếu ứng dụng của bạn cung cấp thông tin về hoạt động của người dùng, chẳng hạn như bước đi hằng ngày, thì bạn nên hiển thị dữ liệu gần như theo thời gian thực về chuyển động của người dùng.
API Cảm biến cung cấp quyền truy cập vào các luồng dữ liệu thô chứa thông tin này. Dữ liệu có thể đến từ các cảm biến có trên thiết bị chạy Android cũng như từ các cảm biến trong các thiết bị đồng hành, chẳng hạn như thiết bị đeo.
Ghi dữ liệu
Nếu ứng dụng của bạn cần thu thập, lưu trữ và đồng bộ hoá dữ liệu về hoạt động thể chất của người dùng, thì bạn có thể sử dụng API Bản ghi. API này lưu trữ dữ liệu về sức khoẻ thể chất và tinh thần bằng cách sử dụng các gói thuê bao. Ứng dụng của bạn chỉ định một hoặc nhiều loại hoạt động cần ghi lại. Sau đó, Google Fit sẽ lưu trữ dữ liệu của các loại đã chỉ định ở chế độ nền ngay cả khi ứng dụng của bạn không chạy. Thao tác này cũng khôi phục các gói thuê bao này khi hệ thống khởi động lại.
Hình 1. Google Fit trên Android.
Dữ liệu trong quá khứ
Nếu muốn người dùng xem được dữ liệu về hoạt động thể dục của các hoạt động trước đây, bạn có thể sử dụng API Lịch sử. API này cấp quyền truy cập vào dữ liệu trước đây về sức khoẻ thể chất và tinh thần, cho phép các ứng dụng thực hiện nhiều thao tác hàng loạt, chẳng hạn như chèn, xoá và đọc dữ liệu.
Phiên
Bản thân dữ liệu thể dục có thể mang lại lợi ích, nhưng dữ liệu sẽ hữu ích hơn khi bạn kết hợp dữ liệu đó với thông tin bổ sung về hoạt động của người dùng. Phiên API nhóm dữ liệu sức khoẻ thể chất và tinh thần (cùng với một số siêu dữ liệu) thành các đơn vị gọi là phiên hoạt động. Phiên hoạt động biểu thị khoảng thời gian người dùng thực hiện một hoạt động thể dục.
Xem và đặt mục tiêu
Ứng dụng của bạn có thể giúp tạo động lực cho người dùng bằng cách so sánh hoạt động thể dục của họ với mục tiêu mà họ đặt ra. API Mục tiêu giúp ứng dụng của bạn hiển thị cho người dùng những mục tiêu về sức khoẻ và thể chất mà họ đã tạo.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-08-31 UTC."],[[["\u003cp\u003eThe Google Fit APIs let your Android app read, record, and store fitness and wellness data from various sources, including BLE devices.\u003c/p\u003e\n"],["\u003cp\u003eApps can use the Recording API to continuously track user activity in the background, even when the app isn't actively running.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can access and manage historical fitness data, enabling users to view past activities and trends through the History API.\u003c/p\u003e\n"],["\u003cp\u003eGoogle Fit allows data to be grouped into sessions, providing context and insights into specific user activities with the Sessions API.\u003c/p\u003e\n"],["\u003cp\u003eApps can leverage the Goals API to display and manage user fitness goals, promoting engagement and motivation.\u003c/p\u003e\n"]]],[],null,["# Android APIs\n\nThe Google Fit APIs for Android are part of [Google Play\nservices](/android/guides/overview). The Google Fit APIs are supported on\nAndroid 4.1 (API level 16) and higher. Using these APIs, your app can do the\nfollowing:\n\n- Read near-real-time and historic data, including data from Bluetooth Low Energy (BLE) devices.\n- Record activities.\n- Associate data with a session.\n- Set fitness goals.\n\nRead sensor data\n----------------\n\nIf your app provides information about a user's activity, such as their daily\nsteps, it can be helpful to show near-real-time data about the user's movements.\nThe [Sensors API](/fit/android/sensors) provides access to streams of raw data\nthat contain this information. The data can come from sensors available on the\nAndroid-powered device as well as from sensors in companion devices, such as\nwearables.\n\nRecord data\n-----------\n\nIf your app needs to gather, store, and sync data about a user's physical\nactivity, you can use the [Recording API](/fit/android/record). This API stores\nhealth and wellness data using subscriptions. Your app specifies one or more\ntypes of activities to record. Google Fit then stores data of the\nspecified types in the background even when your app isn't running. It also\nrestores these subscriptions when the system is restarted. \n**Figure 1.** Google Fit on Android.\n\nHistorical data\n---------------\n\nIf you want users to be able to view fitness data from past activities, you can\nuse the [History API](/fit/android/history). This API provides access to the\nhistorical health and wellness data and lets apps perform bulk operations, such\nas inserting, deleting, and reading data.\n\nSessions\n--------\n\nFitness data can be beneficial by itself, but the data is more useful when you\ncombine it with additional information about the user's activity. The [Sessions\nAPI](/fit/android/using-sessions) bundles health and wellness data, along with\nsome metadata, into units called *sessions*. Sessions represent a time interval\nduring which the user performs a fitness activity.\n\nView and set goals\n------------------\n\nYour app can help motivate users by showing how their fitness activity compares\nto the goals that they've set. The [Goals API](/fit/android/goals) helps your\napp show users the health and fitness goals that they've created."]]