com.google.android.gms.fitness.data.Subscription Java Examples

The following examples show how to use com.google.android.gms.fitness.data.Subscription. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DataManager.java    From GoogleFitExample with Apache License 2.0 6 votes vote down vote up
/**
 * Fetch 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.
 */
private void dumpSubscriptionsList() {
    Log.i(TAG, "Dumping subscriptions.");
    // [START list_current_subscriptions]
    Fitness.RecordingApi.listSubscriptions(mClient)
            // Create the callback to retrieve the list of subscriptions asynchronously.
            .setResultCallback(new ResultCallback<ListSubscriptionsResult>() {
                @Override
                public void onResult(ListSubscriptionsResult listSubscriptionsResult) {
                    for (Subscription sc : listSubscriptionsResult.getSubscriptions()) {
                        DataType dt = sc.getDataType();
                        Log.i(TAG, "Active subscription for data type: " + dt.getName());
                    }
                }
            });
    // [END list_current_subscriptions]
}
 
Example #2
Source File: DataManager.java    From GoogleFitExample with Apache License 2.0 5 votes vote down vote up
private void listSubscriptions() {
    Fitness.RecordingApi.listSubscriptions(mClient).setResultCallback(new ResultCallback<ListSubscriptionsResult>() {
        @Override
        public void onResult(ListSubscriptionsResult result) {
            for (Subscription sc : result.getSubscriptions()) {
                DataType dt = sc.getDataType();
                Log.i(TAG, "found subscription for data type: " + dt.getName());
            }
        }
    });
}
 
Example #3
Source File: DataManager.java    From GoogleFitExample with Apache License 2.0 5 votes vote down vote up
private void unsubscribeAll() {
    if (isConnected()) {
        Fitness.RecordingApi.listSubscriptions(mClient).setResultCallback(new ResultCallback<ListSubscriptionsResult>() {
            @Override
            public void onResult(ListSubscriptionsResult result) {
                for (Subscription sc : result.getSubscriptions()) {
                    DataType dt = sc.getDataType();
                    Log.i(TAG, "Unsubscribing: " + dt.getName());
                    Fitness.RecordingApi.unsubscribe(mClient, sc)
                            .setResultCallback(new ResultCallback<Status>() {
                                @Override
                                public void onResult(Status status) {
                                    if (status.isSuccess()) {
                                        Log.i(TAG, "Successfully unsubscribed for data type: step count delta");
                                    } else {
                                        // Subscription not removed
                                        Log.i(TAG, "Failed to unsubscribe for data type: step count delta");
                                    }
                                }
                            });
                }
            }
        });
    } else {
        Context context = getApplicationContext();
        if (context != null) {
            Toast.makeText(context, "Error: mClient not connected.", Toast.LENGTH_LONG).show();
        }
    }
}
 
Example #4
Source File: MainActivity.java    From AndroidDemoProjects with Apache License 2.0 5 votes vote down vote up
private void initCallbacks() {
    mSubscribeResultCallback = new ResultCallback<Status>() {
        @Override
        public void onResult(@NonNull Status status) {
            if (status.isSuccess()) {
                if (status.getStatusCode() == FitnessStatusCodes.SUCCESS_ALREADY_SUBSCRIBED) {
                    Log.e( "RecordingAPI", "Already subscribed to the Recording API");
                } else {
                    Log.e("RecordingAPI", "Subscribed to the Recording API");
                }
            }
        }
    };

    mCancelSubscriptionResultCallback = new ResultCallback<Status>() {
        @Override
        public void onResult(@NonNull Status status) {
            if (status.isSuccess()) {
                Log.e( "RecordingAPI", "Canceled subscriptions!");
            } else {
                // Subscription not removed
                Log.e("RecordingAPI", "Failed to cancel subscriptions");
            }
        }
    };

    mListSubscriptionsResultCallback = new ResultCallback<ListSubscriptionsResult>() {
        @Override
        public void onResult(@NonNull ListSubscriptionsResult listSubscriptionsResult) {
            for (Subscription subscription : listSubscriptionsResult.getSubscriptions()) {
                DataType dataType = subscription.getDataType();
                Log.e( "RecordingAPI", dataType.getName() );
                for (Field field : dataType.getFields() ) {
                    Log.e( "RecordingAPI", field.toString() );
                }
            }
        }
    };
}