Google Fit REST API के साथ-साथ, Google Fit के सभी एपीआई 2026 में बंद कर दिए जाएंगे. डेवलपर, 1 मई, 2024 से इन एपीआई का इस्तेमाल करने के लिए साइन अप नहीं कर सकते.
देखें कि क्या उपयोगकर्ता ने पहले ज़रूरी डेटा ऐक्सेस करने की अनुमति दी है. साथ ही,
नहीं, तो ऑथराइज़ेशन फ़्लो शुरू करें:
if(!GoogleSignIn.hasPermissions(account,fitnessOptions)){GoogleSignIn.requestPermissions(this,// your activityGOOGLE_FIT_PERMISSIONS_REQUEST_CODE,// e.g. 1account,fitnessOptions)}else{accessGoogleFit()}
अगर ऑथराइज़ेशन फ़्लो ज़रूरी हो, तो उपयोगकर्ता के जवाब को मैनेज करें:
overridefunonActivityResult(requestCode:Int,resultCode:Int,data:Intent?){super.onActivityResult(requestCode,resultCode,data)when(resultCode){Activity.RESULT_OK->when(requestCode){GOOGLE_FIT_PERMISSIONS_REQUEST_CODE->accessGoogleFit()else->{// Result wasn't from Google Fit}}else->{// Permission not granted}}}
जब उपयोगकर्ता, अनुरोध किए गए डेटा को ऐक्सेस करने की अनुमति दे दे, तब अपने ऐप्लिकेशन के मकसद और ज़रूरतों के आधार पर, फ़िटनेस क्लाइंट बनाएं. उदाहरण के लिए, HistoryClient, फ़िटनेस से जुड़ा पुराना डेटा पढ़ने और/या उसमें बदलाव करने के लिए:
privatefunaccessGoogleFit(){valend=LocalDateTime.now()valstart=end.minusYears(1)valendSeconds=end.atZone(ZoneId.systemDefault()).toEpochSecond()valstartSeconds=start.atZone(ZoneId.systemDefault()).toEpochSecond()valreadRequest=DataReadRequest.Builder().aggregate(DataType.AGGREGATE_STEP_COUNT_DELTA).setTimeRange(startSeconds,endSeconds,TimeUnit.SECONDS).bucketByTime(1,TimeUnit.DAYS).build()valaccount=GoogleSignIn.getAccountForExtension(this,fitnessOptions)Fitness.getHistoryClient(this,account).readData(readRequest).addOnSuccessListener({response->
// Use response data hereLog.i(TAG,"OnSuccess()")}).addOnFailureListener({e->Log.d(TAG,"OnFailure()",e)})}
[[["समझने में आसान है","easyToUnderstand","thumb-up"],["मेरी समस्या हल हो गई","solvedMyProblem","thumb-up"],["अन्य","otherUp","thumb-up"]],[["वह जानकारी मौजूद नहीं है जो मुझे चाहिए","missingTheInformationINeed","thumb-down"],["बहुत मुश्किल है / बहुत सारे चरण हैं","tooComplicatedTooManySteps","thumb-down"],["पुराना","outOfDate","thumb-down"],["अनुवाद से जुड़ी समस्या","translationIssue","thumb-down"],["सैंपल / कोड से जुड़ी समस्या","samplesCodeIssue","thumb-down"],["अन्य","otherDown","thumb-down"]],["आखिरी बार 2025-08-31 (UTC) को अपडेट किया गया."],[[["\u003cp\u003eThis code snippet demonstrates how to build a Fitness API client to read aggregate step count data.\u003c/p\u003e\n"],["\u003cp\u003eIt highlights the importance of requesting only necessary data types to improve user consent rates.\u003c/p\u003e\n"],["\u003cp\u003eThe example guides developers through creating \u003ccode\u003eFitnessOptions\u003c/code\u003e, handling user authorization, and accessing historical fitness data using \u003ccode\u003eHistoryClient\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eIt showcases how to query and retrieve aggregate step count data within a specified time frame.\u003c/p\u003e\n"]]],[],null,[]]