Google Fit REST API के साथ-साथ, Google Fit के सभी एपीआई 2026 में बंद कर दिए जाएंगे. डेवलपर, 1 मई, 2024 से इन एपीआई का इस्तेमाल करने के लिए साइन अप नहीं कर सकते.
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 API में मौजूद डेटा सोर्स की प्रॉपर्टी होती हैं. कैप्चर करने के लिए
कस्टम डेटा के लिए, आपको डेटा सोर्स बनाना होगा और उसके बाद डेटा टाइप तय करना होगा:
नया डेटा सोर्स बनाने के लिए, REST API को कॉल करें. उदाहरण के लिए, FlexibilityMeasure.
डेटा टाइप को कोई यूनीक नाम दें, ताकि कैप्चर किए जा रहे डेटा की सटीक जानकारी मिल सके.
डेटा टाइप और उनके फ़ॉर्मैट के फ़ील्ड की जानकारी दें.
अगर आपका डेटा सोर्स बन गया है, तो आपको एक 200 OK एचटीटीपी मिलेगा
रिस्पॉन्स स्टेटस कोड डालें. जवाब के मुख्य हिस्से में, JSON फ़ॉर्मैट में दिखाया गया है
डेटा सोर्स के साथ-साथ datasource.dataStreamId प्रॉपर्टी. इस आईडी का इस्तेमाल करें
डेटा जोड़ने के लिए dataSourceId के तौर पर.
कस्टम डेटा टाइप का इस्तेमाल करना
Android
स्ट्रिंग से अपने कस्टम डेटा टाइप का नाम बदलें
(com.packagename.appname.custom_data_type) DataType ऑब्जेक्ट में
ConfigClient.readDataType तरीका. डालने के लिए, लौटाए गए ऑब्जेक्ट का इस्तेमाल करें
और कस्टम डेटा पढ़ें.
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}")}
आराम
अपने कस्टम डेटा टाइप का इस्तेमाल करके, कस्टम डेटा जोड़ने या पढ़ने के लिए, आपको उनके डेटा की ज़रूरत होगी
स्रोत. किसी कस्टम डेटा टाइप के डेटा सोर्स की जांच करने के लिए, GET भेजें
REST API को ऐक्सेस करने का अनुरोध.
कस्टम डेटा जोड़ना
पसंद के मुताबिक डेटा शामिल करने के लिए, नए डेटा पॉइंट के साथ डेटासेट बनाएं. यह जानकारी दें
आपके कस्टम डेटा टाइप के लिए बनाया गया डेटा सोर्स. डेटा पॉइंट के लिए ज़रूरी है कि
आपके कस्टम डेटा टाइप में बताए गए सभी सही फ़ील्ड और फ़ॉर्मैट हों.
कस्टम डेटा का डेटा फ़ेच किया जा रहा है
कस्टम डेटा पढ़ने के लिए, वह डेटा सोर्स तय करें जिसे आपने अपने कस्टम डेटा के लिए बनाया है
डेटा टाइप को सेव करता है, जब आप Google Fit प्लैटफ़ॉर्म से डेटा पॉइंट वापस लाते हैं.
[null,null,["आखिरी बार 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."]]