Le API Google Fit, inclusa l'API REST di Google Fit, verranno ritirate nel 2026. A partire dal 1° maggio 2024, gli sviluppatori non possono registrarsi per utilizzare queste API.
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Se la tua app deve acquisire informazioni non ancora coperte da una delle
tipi di dati esistenti sulla piattaforma Google Fit, puoi creare un tipo di dati personalizzato.
Creazione di tipi di dati personalizzati
Crea o specifica un tipo di dati personalizzato per acquisire dati personalizzati. Quando crei
tipi di dati personalizzati, accertati che:
Il nome del tipo di dati rappresenta accuratamente i dati sottostanti.
Il prefisso del nome del tipo di dati corrisponde al nome del pacchetto dell'app.
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
I tipi di dati sono una proprietà delle origini dati nell'API REST. Per acquisire
personalizzati, devi creare un'origine dati e specificare il tipo di dati:
Chiama l'API REST per creare una nuova origine dati. Ad esempio, FlexibilityMeasure.
Assegna al tipo di dati un nome univoco che rappresenti da vicino i dati che sta acquisendo.
Specifica i campi del tipo di dati e i relativi formati.
Se l'origine dati è stata creata correttamente, riceverai un messaggio HTTP 200 OK
codice di stato della risposta. Il corpo della risposta contiene una rappresentazione JSON
l'origine dati, inclusa una proprietà datasource.dataStreamId. Utilizza questo ID
come dataSourceId per aggiungere dati.
Utilizzo di tipi di dati personalizzati
Android
Converti il nome del tipo di dati personalizzato da una stringa
(com.nomepacchetto.nomeapp.custom_data_type) in un oggetto DataType utilizzando il metodo
ConfigClient.readDataType. Utilizza l'oggetto restituito per inserire
e leggere i dati personalizzati.
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
Per aggiungere o leggere i dati personalizzati utilizzando i tuoi tipi di dati personalizzati, devi disporre dei relativi dati
fonti. Per controllare le origini dati di un tipo di dati personalizzato, invia un GET
all'API REST.
Aggiunta di dati personalizzati
Per inserire dati personalizzati, crea un set di dati con nuovi punti dati. Specifica
che hai creato per il tuo tipo di dati personalizzato. I punti dati devono
Avere tutti i campi e i formati corretti specificati nel tipo di dati personalizzato.
Lettura dei dati personalizzati
Per leggere i dati personalizzati, specifica l'origine dati che hai creato per il tuo
tipo di dati quando recuperi i punti dati dalla piattaforma Google Fit.
[null,null,["Ultimo aggiornamento 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."]]