本文整理汇总了Java中com.google.android.gms.fitness.Fitness类的典型用法代码示例。如果您正苦于以下问题:Java Fitness类的具体用法?Java Fitness怎么用?Java Fitness使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Fitness类属于com.google.android.gms.fitness包,在下文中一共展示了Fitness类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doInBackground
import com.google.android.gms.fitness.Fitness; //导入依赖的package包/类
@Override
protected Void doInBackground(Void... params) {
DataDeleteRequest request = new DataDeleteRequest.Builder()
.setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS)
.addDataType(DataType.TYPE_WEIGHT)
.build();
com.google.android.gms.common.api.Status insertStatus =
Fitness.HistoryApi.deleteData(googleFitManager.getGoogleApiClient(), request)
.await(1, TimeUnit.MINUTES);
if (insertStatus.isSuccess()) {
Log.w("myLog", "+Successfully deleted data.");
} else {
Log.w("myLog", "+Failed to delete data.");
}
return null;
}
示例2: findFitnessDataSources
import com.google.android.gms.fitness.Fitness; //导入依赖的package包/类
public void findFitnessDataSources() {
DataSourcesRequest dataSourceRequest = new DataSourcesRequest.Builder()
.setDataTypes(DataType.TYPE_STEP_COUNT_DELTA, DataType.TYPE_STEP_COUNT_CUMULATIVE)
.setDataSourceTypes( DataSource.TYPE_DERIVED)
.build();
ResultCallback<DataSourcesResult> dataSourcesResultCallback = new ResultCallback<DataSourcesResult>() {
@Override
public void onResult(DataSourcesResult dataSourcesResult) {
for (DataSource dataSource : dataSourcesResult.getDataSources()) {
DataType type = dataSource.getDataType();
if (DataType.TYPE_STEP_COUNT_DELTA.equals(type)
|| DataType.TYPE_STEP_COUNT_CUMULATIVE.equals(type)) {
Log.i(TAG, "Register Fitness Listener: " + type);
registerFitnessDataListener(dataSource, type);//DataType.TYPE_STEP_COUNT_DELTA);
}
}
}
};
Fitness.SensorsApi.findDataSources(googleFitManager.getGoogleApiClient(), dataSourceRequest)
.setResultCallback(dataSourcesResultCallback);
}
示例3: registerFitnessDataListener
import com.google.android.gms.fitness.Fitness; //导入依赖的package包/类
private void registerFitnessDataListener(DataSource dataSource, DataType dataType) {
SensorRequest request = new SensorRequest.Builder()
.setDataSource(dataSource)
.setDataType(dataType)
.setSamplingRate(3, TimeUnit.SECONDS)
.build();
Fitness.SensorsApi.add(googleFitManager.getGoogleApiClient(), request, this)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
if (status.isSuccess()) {
Log.i(TAG, "SensorApi successfully added");
}
}
});
}
示例4: GoogleFitStepsColumn
import com.google.android.gms.fitness.Fitness; //导入依赖的package包/类
public GoogleFitStepsColumn(Context context, Typeface paintTypeface, Float paintTextSize, int paintColor) {
super(context, paintTypeface, paintTextSize, paintColor);
googleApiClient = new GoogleApiClient.Builder(context)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Fitness.HISTORY_API)
.addApi(Fitness.RECORDING_API)
// When user has multiple accounts, useDefaultAccount() allows Google Fit to
// associated with the main account for steps. It also replaces the need for
// a scope request.
.useDefaultAccount()
.build();
googleApiClient.connect();
if (EmulatorHelper.isEmulator()) {
setText(withSuffix(1801));
}
}
示例5: subscribeToSteps
import com.google.android.gms.fitness.Fitness; //导入依赖的package包/类
/**
* Subscribe 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.
*/
private void subscribeToSteps() {
Fitness.RecordingApi.subscribe(googleApiClient, DataType.TYPE_STEP_COUNT_DELTA)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
if (status.isSuccess()) {
if (status.getStatusCode()
== FitnessStatusCodes.SUCCESS_ALREADY_SUBSCRIBED) {
Log.i(TAG, "Existing subscription for activity detected.");
} else {
Log.i(TAG, "Successfully subscribed!");
}
} else {
Log.i(TAG, "There was a problem subscribing.");
}
}
});
}
示例6: unsubscribeFromSteps
import com.google.android.gms.fitness.Fitness; //导入依赖的package包/类
/**
* Cancel the ACTIVITY_SAMPLE subscription by calling unsubscribe on that {@link DataType}.
*/
private void unsubscribeFromSteps() {
final String dataTypeStr = DataType.TYPE_STEP_COUNT_DELTA.toString();
Log.i(TAG, "Unsubscribing from data type: " + dataTypeStr);
// Invoke the Recording API to unsubscribe from the data type and specify a callback that
// will check the result.
Fitness.RecordingApi.unsubscribe(googleApiClient, DataType.TYPE_ACTIVITY_SAMPLE)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
if (status.isSuccess()) {
Log.i(TAG, "Successfully unsubscribed for data type: " + dataTypeStr);
} else {
// Subscription not removed
Log.i(TAG, "Failed to unsubscribe for data type: " + dataTypeStr);
}
}
});
}
示例7: onCreate
import com.google.android.gms.fitness.Fitness; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.historydata_layout);
mClient = new GoogleApiClient.Builder(this)
.addApi(Fitness.HISTORY_API)
.addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ))
.addScope(new Scope(Scopes.FITNESS_BODY_READ))
.addScope(new Scope(Scopes.FITNESS_LOCATION_READ))
.addScope(new Scope(Scopes.FITNESS_NUTRITION_READ))
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
mAggregateCheckBox = (CheckBox)findViewById(R.id.aggregatecheckbox);
mStartDateText = (TextView)findViewById(R.id.startdate);
mEndDateText = (TextView)findViewById(R.id.enddate);
mResultsText = (TextView)findViewById(R.id.results);
setUpSpinnerDropDown();
setUpListView();
}
示例8: onCreate
import com.google.android.gms.fitness.Fitness; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.subscriptiondata_layout);
mClient = new GoogleApiClient.Builder(this)
.addApi(Fitness.RECORDING_API)
.addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ))
.addScope(new Scope(Scopes.FITNESS_BODY_READ))
.addScope(new Scope(Scopes.FITNESS_LOCATION_READ))
.addScope(new Scope(Scopes.FITNESS_NUTRITION_READ))
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
setUpSpinnerDropDown();
setUpListView();
}
开发者ID:PacktPublishing,项目名称:Android-Sensor-Programming-By-Example,代码行数:19,代码来源:SubscriptionActivity.java
示例9: listExistingSubscription
import com.google.android.gms.fitness.Fitness; //导入依赖的package包/类
public void listExistingSubscription() {
Fitness.RecordingApi.listSubscriptions(mClient)
.setResultCallback(new ResultCallback<ListSubscriptionsResult>() {
@Override
public void onResult(ListSubscriptionsResult listSubscriptionsResult) {
mDataTypeList.clear();
for (Subscription sc : listSubscriptionsResult.getSubscriptions()) {
mDataTypeList.add(sc.getDataType());
}
runOnUiThread(new Runnable() {
@Override
public void run() {
mListAdapter.notifyDataSetChanged();
}
});
}
});
}
开发者ID:PacktPublishing,项目名称:Android-Sensor-Programming-By-Example,代码行数:20,代码来源:SubscriptionActivity.java
示例10: removeSubscription
import com.google.android.gms.fitness.Fitness; //导入依赖的package包/类
public void removeSubscription(DataType mDataType) {
Fitness.RecordingApi.unsubscribe(mClient, mDataType)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
if (status.isSuccess()) {
runOnUiThread(new Runnable() {
@Override
public void run() {
mDataTypeList.remove(lastRemovedPosition);
mListAdapter.notifyDataSetChanged();
}
});
} else {
Log.i(TAG, "Failed to unsubscribe ");
}
}
});
}
开发者ID:PacktPublishing,项目名称:Android-Sensor-Programming-By-Example,代码行数:21,代码来源:SubscriptionActivity.java
示例11: onCreate
import com.google.android.gms.fitness.Fitness; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sensordata_layout);
mLiveDataText = (TextView)findViewById(R.id.livedata);
setUpSpinnerDropDown();
setUpListView();
mClient = new GoogleApiClient.Builder(this)
.addApi(Fitness.SENSORS_API)
.addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ))
.addScope(new Scope(Scopes.FITNESS_BODY_READ))
.addScope(new Scope(Scopes.FITNESS_LOCATION_READ))
.addScope(new Scope(Scopes.FITNESS_NUTRITION_READ))
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
示例12: listDataSources
import com.google.android.gms.fitness.Fitness; //导入依赖的package包/类
public void listDataSources(DataType mDataType)
{
Fitness.SensorsApi.findDataSources(mClient, new DataSourcesRequest.Builder()
.setDataTypes(mDataType)
.setDataSourceTypes(DataSource.TYPE_DERIVED)
.setDataSourceTypes(DataSource.TYPE_RAW)
.build())
.setResultCallback(new ResultCallback<DataSourcesResult>() {
@Override
public void onResult(DataSourcesResult dataSourcesResult) {
mListAdapter.notifyDataSetChanged();
if (dataSourcesResult.getDataSources().size() > 0) {
mDataSourceList.addAll(dataSourcesResult.getDataSources());
mLiveDataText.setText("Please select from following data source to get the live data");
} else {
mLiveDataText.setText("No data source found for selected data type");
}
}
});
}
示例13: addDataListener
import com.google.android.gms.fitness.Fitness; //导入依赖的package包/类
public void addDataListener(DataSource mDataSource)
{
Fitness.SensorsApi.add(mClient,
new SensorRequest.Builder()
.setDataSource(mDataSource)
.setDataType(mDataSource.getDataType())
.setSamplingRate(1, TimeUnit.SECONDS)
.build(), mOnDataPointListener)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
if (status.isSuccess()) {
mLiveDataText.setText("Listener registered successfully, waiting for live data");
isDataListenerAdded = true;
} else {
mLiveDataText.setText("Listener registration failed");
}
}
});
}
示例14: startApiConnection
import com.google.android.gms.fitness.Fitness; //导入依赖的package包/类
/**
* start a google api connection. Gets all of the permissions necessary for the entire app.
* @param c context from which to generate the client. The context must be active for the application
* lifetime. We are assuming that MainActivity is active always when app is being displayed,
* and we also assume that loggers are active for the lifetime of the application
*/
private synchronized void startApiConnection(Context c) {
apiResolving = true;
apiClient = new GoogleApiClient.Builder(c)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
// Add the google APIs you want to use HERE, and a comment specifying which logger uses them
.addApi(LocationServices.API) // LocationLogger
.addApi(Fitness.RECORDING_API)
.addApi(Fitness.HISTORY_API)
.addScope(Fitness.SCOPE_ACTIVITY_READ)
.addScope(Fitness.SCOPE_BODY_READ)
.addScope(Fitness.SCOPE_LOCATION_READ).build();
apiClient.connect();
Log.i(TAG, "Connecting to Google APIs...");
}
示例15: subscribe
import com.google.android.gms.fitness.Fitness; //导入依赖的package包/类
public void subscribe() {
//connect to the step count.
Fitness.getRecordingClient(getActivity(), GoogleSignIn.getLastSignedInAccount(getContext()))
.subscribe(DataType.TYPE_STEP_COUNT_DELTA)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
logthis("Subscribed to the Recording API");
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
logthis("failed to subscribe to the Recording API");
}
});
}