API Google Fit, termasuk Google Fit REST API, tidak akan digunakan lagi pada tahun 2026. Mulai 1 Mei 2024, developer tidak dapat mendaftar untuk menggunakan API ini.
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Jika aplikasi Anda perlu mengambil informasi yang belum dicakup oleh salah satu
tipe data yang sudah ada di platform Google Fit, Anda dapat membuat jenis data kustom.
Membuat jenis data kustom
Buat atau tentukan jenis data kustom untuk mengambil data kustom. Saat Anda membuat
jenis data khusus, pastikan:
Nama jenis data mewakili data pokok secara akurat.
Awalan nama jenis data cocok dengan nama paket aplikasi Anda.
valrequest=DataTypeCreateRequest.Builder()// The prefix of your data type name must match your app's package name.setName("com.packagename.appname.custom_data_type")// Add some custom fields, both int and float.addField("field1",Field.FORMAT_INT32).addField("field2",Field.FORMAT_FLOAT)// Add some common fields.addField(Field.FIELD_ACTIVITY).build()Fitness.getConfigClient(this,account).createCustomDataType(request).addOnSuccessListener{dataType->
// Use this custom data type to insert data into your app.Log.d(TAG,"Created data type: ${dataType.name}")}
REST
Jenis data adalah properti sumber data, di REST API. Untuk mengambil
data kustom, Anda harus membuat sumber data lalu menentukan jenis datanya:
Panggil REST API untuk membuat sumber data baru. Misalnya, FlexibilityMeasure.
Berikan nama unik pada tipe data, yang menggambarkan data yang diambilnya.
Jika sumber data berhasil dibuat, Anda akan mendapatkan HTTP 200 OK
kode status respons Anda. Isi respons berisi representasi JSON dari
sumber data, termasuk properti datasource.dataStreamId. Gunakan ID ini
sebagai dataSourceId untuk menambahkan data.
Menggunakan jenis data kustom
Android
Mengonversi nama jenis data kustom dari string
(com.packagename.appname.custom_data_type) ke dalam objek DataType menggunakan
Metode ConfigClient.readDataType. Gunakan objek yang ditampilkan untuk menyisipkan
dan membaca data kustom.
Fitness.getConfigClient(this,account).readDataType("com.packagename.appname.custom_data_type").addOnSuccessListener{dataType->
// Use this custom data type to insert data into your app.Log.d(TAG,"Retrieved data type: ${dataType.name}")}
REST
Untuk menambahkan atau membaca data kustom menggunakan jenis data kustom, Anda memerlukan data mereka
sumber. Untuk memeriksa sumber data jenis data kustom, kirim GET
ke REST API.
Menambahkan data kustom
Untuk menyisipkan data kustom, buat set data dengan titik data baru. Tentukan
sumber data yang Anda buat untuk jenis data kustom Anda. Titik-titik data itu perlu
memiliki semua kolom dan format yang benar yang ditentukan dalam jenis data kustom Anda.
Membaca data kustom
Untuk membaca data kustom, tentukan sumber data yang Anda buat untuk kustom
jenis data saat Anda mengambil titik data dari platform Google Fit.
[null,null,["Terakhir diperbarui pada 2025-08-31 UTC."],[[["\u003cp\u003eDevelop custom data types to capture unique fitness data specific to your app, ensuring the data type name reflects the data and uses your app's package name as a prefix.\u003c/p\u003e\n"],["\u003cp\u003eCreate custom data types in Android using the \u003ccode\u003eConfigClient.createCustomDataType\u003c/code\u003e method and in REST by creating a new data source with a unique name and defined fields.\u003c/p\u003e\n"],["\u003cp\u003eUse the \u003ccode\u003eConfigClient.readDataType\u003c/code\u003e method in Android or send a \u003ccode\u003eGET\u003c/code\u003e request to the REST API to access your custom data type for inserting and reading data.\u003c/p\u003e\n"],["\u003cp\u003eInsert custom data by creating a dataset with data points corresponding to your custom data type's fields and specifying the associated data source.\u003c/p\u003e\n"],["\u003cp\u003eRead custom data by specifying the data source linked to your custom data type when retrieving data points from the Google Fit platform.\u003c/p\u003e\n"]]],[],null,["# Custom data types\n\nIf your app needs to capture information that isn't already covered by one of the\nexisting data types on the Google Fit platform, you can create a custom data type.\n| **Note:** Custom data types are only available to the apps that created them. Other apps can't see or use your custom data types.\n\nCreating custom data types\n--------------------------\n\nCreate, or specify, a custom data type to capture custom data. When you create\ncustom data types, make sure:\n\n- The data type name accurately represents the underlying data.\n- The prefix of the data type name matches your app's package name.\n\n### Android\n\nTo create a custom data type for the first time, use the\n[`ConfigClient.createCustomDataType`](/android/gms/fitness/ConfigClient#create%0ACustomDataType(com.google.android.gms.fitness.request.DataTypeCreateRequest))\nmethod: \n\n val request = DataTypeCreateRequest.Builder()\n // The prefix of your data type name must match your app's package name\n .setName(\"com.packagename.appname.custom_data_type\") // Add some custom fields, both int and float\n .addField(\"field1\", Field.FORMAT_INT32)\n .addField(\"field2\", Field.FORMAT_FLOAT)\n // Add some common fields\n .addField(Field.FIELD_ACTIVITY)\n .build()\n\n Fitness.getConfigClient(this, account)\n .createCustomDataType(request)\n .addOnSuccessListener { dataType -\u003e\n // Use this custom data type to insert data into your app.\n Log.d(TAG, \"Created data type: ${dataType.name}\")\n }\n\n### REST\n\nData types are a property of data sources, in the REST API. To capture\ncustom data, you need to create a data source and then specify the data type:\n\n1. Call the REST API to create a *new data source* . For example, `FlexibilityMeasure`.\n2. Give the data type a unique name, that closely represents the data it's capturing.\n\n | **Note:** This name can be anything, as long as it's unique and doesn't have the same name as another data type. We recommend this convention: com.packagename.appname.custom_data_type\n3. Specify the fields of the data type, and their formats.\n\n**HTTP method** \n\n POST\n\n**Request URL** \n\n https://www.googleapis.com/fitness/v1/users/me/dataSources\n\n**Request body** \n\n {\n \"dataStreamName\": \"FlexibilityMeasure\",\n \"type\": \"raw\",\n \"application\": {\n \"detailsUrl\": \"http://recoveryapps.com\",\n \"name\": \"Stretch Flex\",\n \"version\": \"1\"\n },\n \"dataType\": {\n \"name\": \"com.recoveryapps.stretchflex.flexibility\",\n \"field\": [\n {\n \"name\": \"ankle_range_degrees\",\n \"format\": \"integer\"\n },\n {\n \"name\": \"wrist_range_degrees\",\n \"format\": \"integer\",\n \"optional\": true\n }\n ]\n }\n }\n\n**Response**\n\nIf your data source was created successfully, you'll get a [`200 OK`](https://httpstatuses.com/200) HTTP\nresponse status code. The response body contains a JSON representation of\nthe data source, including a `datasource.dataStreamId` property. Use this ID\nas the `dataSourceId` to add data.\n\nUsing custom data types\n-----------------------\n\n### Android\n\nConvert your custom data type's name from a string\n(com.packagename.appname.custom_data_type) into a `DataType` object using the\n[`ConfigClient.readDataType`](/android/reference/com/google/android/gms/fitness/ConfigClient#readDataType(java.lang.String)) method. Use the returned object to [insert](/android/reference/com/google/android/gms/fitness/HistoryClient#public-taskvoid-insertdata-dataset-dataset)\nand [read](/android/reference/com/google/android/gms/fitness/ConfigClient#public-taskdatatype-readdatatype-string-datatypename) custom data. \n\n Fitness.getConfigClient(this, account)\n .readDataType(\"com.packagename.appname.custom_data_type\")\n .addOnSuccessListener { dataType -\u003e\n // Use this custom data type to insert data into your app.\n Log.d(TAG, \"Retrieved data type: ${dataType.name}\")\n }\n\n### REST\n\nTo add or read custom data using your custom data types, you need their data\nsources. To check the data sources of a custom data type, [send a `GET`\nrequest to the REST API](/fit/rest/v1/reference/users/dataSources/list).\n\n### Adding custom data\n\nTo insert custom data, create a dataset with new data points. Specify the\ndata source you created for your custom data type. The data points need to\nhave all the correct fields and formats specified in your custom data type.\n\n### Reading custom data\n\nTo read custom data, specify the data source you created for your custom\ndata type when you retrieve data points from the Google Fit platform."]]