2

I do Pedometer app for android. The principle of operation as follows: When you first launch the app, runs a service that runs in the foreground mode. Program prompts the user for Google account to login. If everything is fine then created GoogleApiClient object. Then in case of successful connection is created Fitness.SensorsApi in which I ask only in the number of steps of the system. Since I keep a not a lot of data, instead of a database I use SharedPreferences, and write new data there. If application is running, mainActivity connect to SharedPreferences every second to display the new values on the screen. All work is not bad. But sometimes, cease come on the number of steps. This may occur during the day sometimes it happens after the reset counters every day at 00:00 and sometimes a few days to work without problems. Helps only a complete restart the application.

And several times was that the data is not displayed on the screen, but the service has worked and recorded data. In this case, after application restart I immediately received the data for the entire period (hung screen). The service itself is 100% live, because I send a message in the log every 5 seconds. If someone is faced with a similar, please help, what could be the reason. Can GoogleApiClient loses connection or something else. How to track down an error? I will be very grateful.

Vlad
  • 149
  • 7

1 Answers1

0

Check this documentation of Google Fit on how to connect your Android app in Google fit. Make sure you properly setup this guide in your project, especially the Step 5 in where you Connect to the fitness service. For more information, check this SO question.

Here is the sample code on how the Sensors API should be accessed from the Fitness entry point.

GoogleApiClient client = new GoogleApiClient.Builder(context)
.addApi(Fitness.SENSORS_API)
...
.build();
client.connect();

PendingResult<Status> pendingResult = Fitness.SensorsApi.add(
client,
new SensorRequest.Builder()
.setDataType(DataType.TYPE_STEP_COUNT_DELTA)
.setSamplingDelay(1, TimeUnit.MINUTES) // sample once per minute
.build(),
myStepCountListener);

For additional information, check this links.

Community
  • 1
  • 1
KENdi
  • 7,576
  • 2
  • 16
  • 31