Interfejsy Google Fit API, w tym interfejs Google Fit API typu REST, zostaną wycofane w 2026 roku. Od 1 maja 2024 r. deweloperzy nie mogą rejestrować się w celu korzystania z tych interfejsów API.
Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
Jeśli aplikacja musi rejestrować informacje, których jeszcze nie obejmuje
istniejących typów danych na platformie Google Fit, możesz utworzyć niestandardowy typ danych.
Tworzenie niestandardowych typów danych
Utwórz lub określ niestandardowy typ danych do rejestrowania niestandardowych danych. Gdy tworzysz
niestandardowych typów danych, upewnij się, że:
Nazwa typu danych dokładnie odzwierciedla dane bazowe.
Prefiks nazwy typu danych pasuje do nazwy pakietu aplikacji.
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
Typy danych są właściwościami źródeł danych w interfejsie API REST. Aby zrobić zdjęcie
danych niestandardowych, musisz utworzyć źródło danych, a następnie określić typ danych:
Wywołaj interfejs API REST, aby utworzyć nowe źródło danych. Na przykład: FlexibilityMeasure.
Nadaj typowi danych unikalną nazwę, która dokładnie odzwierciedla dane, które rejestruje.
Jeśli źródło danych zostało utworzone, otrzymasz żądanie HTTP 200 OK
kodu stanu odpowiedzi. Treść odpowiedzi zawiera reprezentację JSON
źródła danych, w tym usługę datasource.dataStreamId. Użyj tego identyfikatora
jako dataSourceId, aby dodać dane.
Używanie niestandardowych typów danych
Android
Konwertowanie nazwy niestandardowego typu danych z ciągu znaków
(com.packagename.appname.custom_data_type) do obiektu DataType za pomocą funkcji
Metoda ConfigClient.readDataType. Użyj zwróconego obiektu do wstawiania
i odczytywanie danych niestandardowych.
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
Aby dodawać lub odczytywać dane niestandardowe za pomocą niestandardowych typów danych, potrzebujesz ich danych
źródeł. Aby sprawdzić źródła danych niestandardowego typu danych, wyślij GET
do interfejsu API REST.
Dodawanie danych niestandardowych
Aby wstawić dane niestandardowe, utwórz zbiór danych z nowymi punktami danych. Podaj wartość
utworzone dla niestandardowego typu danych. Punkty danych muszą
mieć wszystkie prawidłowe pola i formaty określone w Twoim niestandardowym typie danych.
Odczyt danych niestandardowych
Aby odczytać dane niestandardowe, podaj źródło danych utworzone dla tego niestandardowego wymiaru
typ danych podczas pobierania punktów danych z platformy Google Fit.
[null,null,["Ostatnia aktualizacja: 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."]]