Google Fit REST API dahil olmak üzere Google Fit API'leri, 30 Haziran 2025'ten sonra kullanılamayacak. 1 Mayıs 2024'ten itibaren geliştiriciler bu API'leri kullanmak için kaydolamayacak.
override fun onActivityResult(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
}
}
}
Kullanıcı, istenen verilere erişim yetkisi verdikten sonra fitness egzersizi oluşturun.
istemci (örneğin, geçmiş fitness verilerini okumak ve/veya yazmak için HistoryClient
verileri) sunmalısınız:
private fun accessGoogleFit() {
val end = LocalDateTime.now()
val start = end.minusYears(1)
val endSeconds = end.atZone(ZoneId.systemDefault()).toEpochSecond()
val startSeconds = start.atZone(ZoneId.systemDefault()).toEpochSecond()
val readRequest = DataReadRequest.Builder()
.aggregate(DataType.AGGREGATE_STEP_COUNT_DELTA)
.setTimeRange(startSeconds, endSeconds, TimeUnit.SECONDS)
.bucketByTime(1, TimeUnit.DAYS)
.build()
val account = GoogleSignIn.getAccountForExtension(this, fitnessOptions)
Fitness.getHistoryClient(this, account)
.readData(readRequest)
.addOnSuccessListener({ response ->
// Use response data here
Log.i(TAG, "OnSuccess()")
})
.addOnFailureListener({ e -> Log.d(TAG, "OnFailure()", e) })
}
[[["Anlaması kolay","easyToUnderstand","thumb-up"],["Sorunumu çözdü","solvedMyProblem","thumb-up"],["Diğer","otherUp","thumb-up"]],[["İhtiyacım olan bilgiler yok","missingTheInformationINeed","thumb-down"],["Çok karmaşık / çok fazla adım var","tooComplicatedTooManySteps","thumb-down"],["Güncel değil","outOfDate","thumb-down"],["Çeviri sorunu","translationIssue","thumb-down"],["Örnek veya kod sorunu","samplesCodeIssue","thumb-down"],["Diğer","otherDown","thumb-down"]],["Son güncelleme tarihi: 2024-08-21 UTC."],[[["This guide demonstrates how to build a Fitness API client in Android to read aggregate step count data."],["It outlines the process of creating a `FitnessOptions` instance to define the data types and access permissions required."],["Users will be prompted to grant necessary permissions during the Google Sign-In authorization flow."],["Upon authorization, the code demonstrates how to access the Google Fit HistoryClient to retrieve and utilize the step count data."],["The example showcases requesting aggregate step data over the past year, bucketed by day, without needing specific Android permissions."]]],[]]