I am trying to connect my application to Google Fit. I am using IntentService, which should do the following. It turns out when I have information about the steps. At this point, I am trying to create a GoogleApiClient by calling the following code:
mClient = new GoogleApiClient.Builder(this) .addApi(Fitness.HISTORY_API) .addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE)) .addScope(new Scope(Scopes.FITNESS_LOCATION_READ_WRITE)) .addConnectionCallbacks( new GoogleApiClient.ConnectionCallbacks() { @Override public void onConnected(Bundle bundle) { log.info("FITNESS_API: Connected!!!"); Thread thread = new Thread(new Runnable() { @Override public void run() { insertOrUpdateDataPoints(); } }); thread.start(); } @Override public void onConnectionSuspended(int i) {
After creating a DataSet and adding step details as DataPoint elements, I synchronize the information with Google Fit and close GoogleApiClient with
com.google.android.gms.common.api.Status insertStatus = Fitness.HistoryApi.insertData(mClient, dataSet).await(1, TimeUnit.MINUTES);
The problem is that when I try to control GoogleApiClient myself (without enableAutoManage), I do not receive an invitation so that the application can send data to Google Fit. This behavior changes if I use enableAutoManage when creating GoogleApiClient. However, in order to enable AutoManage for the client, I need to have an ActivityFragment due to the parameters needed to enableAutoManage. I do not have access to the ActivityFragment in the IntentyService, and I want to keep the client management and the paste action in a separate service that can run in the background.
Also, when I do not use enableAutoManage, although I registered a connect callback for GoogleApiClient, nothing happens.
How can I guarantee that my application will prompt the user to allow the application to send messages to Google Fit? I need this to happen if the application does not have permission to publish to Google Fit when the user opens the application. Any ideas? Thanks.
android google-fit
Vlad Bogdan
source share