Courtesy: GitHub

Android Fit Recording Api Sessions Sample

A simple example of how to use the Recording API on the Android Fit platform.

Getting Started

This sample uses the Gradle build system. To build this project, use the "gradlew build" command or use "Import Project" in Android Studio.

NOTE: You must register an Android client underneath a Google Project in order for the Google Fit API to become available for your app. The process ensures your app has proper consent screen information for users to accept, among other things required to access Google APIs. See the instructions for more details: http://developers.google.com/fit/android/get-started

Support

The most common problem using these samples is a SIGN_IN_FAILED exception. Users can experience this after selecting a Google Account to connect to the FIT API. If you see the following in logcat output then make sure to register your Android app underneath a Google Project as outlined in the instructions for using this sample at: http://developers.google.com/fit/android/get-started

10-26 14:40:37.082 1858-2370/? E/MDM: [138] b.run: Couldn't connect to Google API client: ConnectionResult{statusCode=API_UNAVAILABLE, resolution=null, message=null}

Use the following channels for support:

If you've found an error in this sample, please file an issue: https://github.com/googlesamples/android-fitness/issues

Patches are encouraged, and may be submitted according to the instructions in CONTRIB.md.

License

Copyright 2014 Google, Inc.

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

compileSdkVersion 26

applicationId "com.google.android.gms.fit.samples.basicrecordingapi"

minSdkVersion 14

targetSdkVersion 26

versionCode 2

versionName "1.1"

compile "com.google.android.gms:play-services-auth:${google_play_services_library}"

compile "com.google.android.gms:play-services-fitness:${google_play_services_library}"

compile "com.android.support:appcompat-v7:${google_support_library}"

compile "com.android.support:design:${google_support_library}"

compile fileTree(dir: 'libs', include: ['*.jar'])

package com.google.android.gms.fit.samples.basicrecordingapi

MainActivity

This sample demonstrates how to use the Recording API of the Google Fit platform to subscribe to data sources, query against existing subscriptions, and remove subscriptions. It also demonstrates how to authenticate a user with Google Play Services.

Subscribes to an available {@link DataType}. Subscriptions can exist across application instances (so data is recorded even after the application closes down). When creating a new subscription, it may already exist from a previous invocation of this app. If the subscription already exists, the method is a no-op. However, you can check this with a special success code.

Fetches a list of all active subscriptions and log it. Since the logger for this sample also prints to the screen, we can see what is happening in this way.

Cancels the ACTIVITY_SAMPLE subscription by calling unsubscribe on that {@link DataType}.

Initializes a custom log class that outputs both to in-app targets and logcat.