本文整理汇总了Java中com.google.android.gms.fitness.request.SensorRequest类的典型用法代码示例。如果您正苦于以下问题:Java SensorRequest类的具体用法?Java SensorRequest怎么用?Java SensorRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SensorRequest类属于com.google.android.gms.fitness.request包,在下文中一共展示了SensorRequest类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: registerFitnessDataListener
import com.google.android.gms.fitness.request.SensorRequest; //导入依赖的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");
}
}
});
}
开发者ID:StasDoskalenko,项目名称:react-native-google-fit,代码行数:19,代码来源:StepCounter.java
示例2: addDataListener
import com.google.android.gms.fitness.request.SensorRequest; //导入依赖的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");
}
}
});
}
开发者ID:PacktPublishing,项目名称:Android-Sensor-Programming-By-Example,代码行数:21,代码来源:SensorActivity.java
示例3: registerFitDataListener
import com.google.android.gms.fitness.request.SensorRequest; //导入依赖的package包/类
/**
* Add SensorsApi listener for real-time display of sensor data. Can be called repeatedly on
* multiple data types.
* @param dataTypeSetting Type of data to listen to.
* @param listener Listener for callbacks from SensorsApi.
*/
private void registerFitDataListener(
FitDataTypeSetting dataTypeSetting, OnDataPointListener listener) {
sensorsAwaitingRegistration.add(dataTypeSetting);
Fitness.SensorsApi.add(
mGoogleApiClient,
new SensorRequest.Builder()
.setDataType(dataTypeSetting.getDataType())
.setSamplingRate(dataTypeSetting.getSamplingRateSeconds(), TimeUnit.SECONDS)
.setAccuracyMode(dataTypeSetting.getAccuracyMode())
.build(),
listener)
.setResultCallback(new FitResultCallback<Status>(
this, FitResultCallback.RegisterType.SENSORS, dataTypeSetting.getDataType(),
true));
}
开发者ID:googlesamples,项目名称:android-play-games-in-motion,代码行数:22,代码来源:GoogleApiClientWrapper.java
示例4: readData
import com.google.android.gms.fitness.request.SensorRequest; //导入依赖的package包/类
@NonNull
public Observable<DataPoint> readData(SensorRequest request) {
return ObservableTask.create(callback -> {
OnDataPointListener listener = dataPoint -> callback.onNext(dataPoint);
callback.setDisposeListener(() -> client.remove(listener));
return client.add(request, listener);
});
}
开发者ID:niqo01,项目名称:RxTask,代码行数:9,代码来源:RxSensorsClient.java
示例5: registerFitnessDataListener
import com.google.android.gms.fitness.request.SensorRequest; //导入依赖的package包/类
/**
* Register a listener with the Sensors API for the provided {@link DataSource} and
* {@link DataType} combo.
*/
private void registerFitnessDataListener(DataSource dataSource, DataType dataType) {
// [START register_data_listener]
mListener = new OnDataPointListener() {
@Override
public void onDataPoint(DataPoint dataPoint) {
for (Field field : dataPoint.getDataType().getFields()) {
Value val = dataPoint.getValue(field);
Log.i(TAG, "Detected DataPoint field: " + field.getName());
Log.i(TAG, "Detected DataPoint value: " + val);
}
}
};
Fitness.SensorsApi.add(
mClient,
new SensorRequest.Builder()
.setDataSource(dataSource) // Optional but recommended for custom data sets.
.setDataType(dataType) // Can't be omitted.
.setSamplingRate(10, TimeUnit.SECONDS)
.build(),
mListener)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
if (status.isSuccess()) {
Log.i(TAG, "Listener registered!");
} else {
Log.i(TAG, "Listener not registered.");
}
}
});
// [END register_data_listener]
}
开发者ID:maseh87,项目名称:androidFitApp,代码行数:38,代码来源:MainActivity.java
示例6: setupSensors
import com.google.android.gms.fitness.request.SensorRequest; //导入依赖的package包/类
public void setupSensors(DataSource dataSource, DataType dataType) {
logthis("Setup Sensors start");
mlistener = new OnDataPointListener() {
@Override
public void onDataPoint(DataPoint dataPoint) {
//we are not on the UI thread!
for (Field field : dataPoint.getDataType().getFields()) {
Value val = dataPoint.getValue(field);
Log.i(TAG, "Detected DataPoint field: " + field.getName());
sendmessage("Detected DataPoint field: " + field.getName());
Log.i(TAG, "Detected DataPoint value: " + val);
sendmessage("Detected DataPoint value: " + val);
}
}
};
Fitness.getSensorsClient(getActivity(), GoogleSignIn.getLastSignedInAccount(getContext()))
.add(
new SensorRequest.Builder()
.setDataSource(dataSource) // Optional but recommended for custom data sets.
.setDataType(dataType) // Can't be omitted.
.setSamplingRate(10, TimeUnit.SECONDS)
.build(),
mlistener)
.addOnCompleteListener(
new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Log.i(TAG, "Listener registered!");
} else {
Log.e(TAG, "Listener not registered.", task.getException());
}
}
});
}
开发者ID:JimSeker,项目名称:googleplayAPI,代码行数:38,代码来源:SensorFragment.java
示例7: registerDataSourceListener
import com.google.android.gms.fitness.request.SensorRequest; //导入依赖的package包/类
private void registerDataSourceListener(DataType dataType) {
onDataPointListener = new OnDataPointListener() {
@Override
public void onDataPoint(DataPoint dataPoint) {
for (Field field : dataPoint.getDataType().getFields()) {
Value aValue = dataPoint.getValue(field);
Log.d(TAG, "registerDataSourceListener onDataPoint L-value= " + field.getName());
Log.d(TAG, "registerDataSourceListener onDataPoint R-value=" + aValue);
addContentToView( "dataPoint=" + field.getName() + "= " + aValue + "\n") ;
}
}
};
Fitness.SensorsApi.add(
googleApiClient,
new SensorRequest.Builder()
// .setDataSource(dataSource)
.setDataType(dataType)
.setSamplingRate(12, TimeUnit.SECONDS)
.setAccuracyMode(SensorRequest.ACCURACY_MODE_DEFAULT)
.build(),
onDataPointListener)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
if (status.isSuccess()) {
Log.d(TAG, "onDataPointListener registered good");
} else {
Log.d(TAG, "onDataPointListener failed to register bad");
}
}
});
}
开发者ID:smitzey,项目名称:wearbooksource,代码行数:38,代码来源:GHelloFitActivity.java
示例8: registerDataSourceListener
import com.google.android.gms.fitness.request.SensorRequest; //导入依赖的package包/类
private void registerDataSourceListener(DataType dataType) {
onDataPointListener = new OnDataPointListener() {
@Override
public void onDataPoint(DataPoint dataPoint) {
for (Field field : dataPoint.getDataType().getFields()) {
Value aValue = dataPoint.getValue(field);
Log.d(TAG, "Detected DataPoint field: " + field.getName());
Log.d(TAG, "Detected DataPoint value: " + aValue);
addContentToView( "dataPoint=" + field.getName() + " " + aValue + "\n") ;
}
}
};
Fitness.SensorsApi.add(
googleApiClient,
new SensorRequest.Builder()
// .setDataSource(dataSource)
.setDataType(dataType)
.setSamplingRate(12, TimeUnit.SECONDS)
.setAccuracyMode(SensorRequest.ACCURACY_MODE_DEFAULT)
.build(),
onDataPointListener)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
if (status.isSuccess()) {
Log.d(TAG, "onDataPointListener registered good");
} else {
Log.d(TAG, "onDataPointListener failed to register bad");
}
}
});
}
开发者ID:smitzey,项目名称:wearbooksource,代码行数:35,代码来源:HelloFitActivity.java
示例9: SensorObservable
import com.google.android.gms.fitness.request.SensorRequest; //导入依赖的package包/类
public SensorObservable(SensorsClient client, SensorRequest request) {
this.client = client;
this.request = request;
}
开发者ID:niqo01,项目名称:RxTask,代码行数:5,代码来源:SensorObservable.java
示例10: listDatasourcesAndSubscribe
import com.google.android.gms.fitness.request.SensorRequest; //导入依赖的package包/类
public void listDatasourcesAndSubscribe() {
Fitness.SensorsApi.findDataSources(client, new DataSourcesRequest.Builder()
.setDataTypes(
DataType.TYPE_STEP_COUNT_DELTA,
DataType.TYPE_DISTANCE_DELTA)
.setDataSourceTypes(DataSource.TYPE_DERIVED)
.build())
.setResultCallback(new ResultCallback<DataSourcesResult>() {
@Override
public void onResult(DataSourcesResult dataSourcesResult) {
datasources.clear();
listeners.clear();
for (DataSource dataSource : dataSourcesResult.getDataSources()) {
Device device = dataSource.getDevice();
String fields = dataSource.getDataType().getFields().toString();
datasources.add(device.getManufacturer() + " " + device.getModel() + " [" + dataSource.getDataType().getName() + " " + fields + "]");
final DataType dataType = dataSource.getDataType();
if (
dataType.equals(DataType.TYPE_STEP_COUNT_DELTA) ||
dataType.equals(DataType.TYPE_DISTANCE_DELTA)) {
final OnDataPointListener listener = new OnDataPointListener() {
@Override
public void onDataPoint(DataPoint dataPoint) {
String msg = "onDataPoint: ";
for (Field field : dataPoint.getDataType().getFields()) {
Value value = dataPoint.getValue(field);
msg += field + "=" + value + ", ";
}
display.show(msg);
}
};
Fitness.SensorsApi.add(client,
new SensorRequest.Builder()
.setDataSource(dataSource)
.setDataType(dataType)
.setSamplingRate(10, TimeUnit.SECONDS)
.build(),
listener)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
if (status.isSuccess()) {
listeners.add(listener);
display.show("Listener for " + dataType.getName() + " registered");
} else {
display.show("Failed to register listener for " + dataType.getName());
}
}
});
}
}
datasourcesListener.onDatasourcesListed();
}
});
}
开发者ID:parthsatra,项目名称:WalkPotato,代码行数:61,代码来源:Sensors.java
示例11: subscribeToHeartRate
import com.google.android.gms.fitness.request.SensorRequest; //导入依赖的package包/类
public void subscribeToHeartRate() {
Fitness.SensorsApi.findDataSources(client, new DataSourcesRequest.Builder()
.setDataTypes( DataType.TYPE_HEART_RATE_BPM )
.setDataSourceTypes(DataSource.TYPE_RAW, DataSource.TYPE_DERIVED)
.build())
.setResultCallback(new ResultCallback<DataSourcesResult>() {
@Override
public void onResult(DataSourcesResult dataSourcesResult) {
datasources.clear();
listeners.clear();
for (DataSource dataSource : dataSourcesResult.getDataSources()) {
Device device = dataSource.getDevice();
String fields = dataSource.getDataType().getFields().toString();
datasources.add(device.getManufacturer() + " " + device.getModel() + " [" + dataSource.getDataType().getName() + " " + fields + "]");
final DataType dataType = dataSource.getDataType();
if (dataType.equals(DataType.TYPE_HEART_RATE_BPM)) {
final OnDataPointListener listener = new OnDataPointListener() {
@Override
public void onDataPoint(DataPoint dataPoint) {
String msg = "onDataPoint: ";
for (Field field : dataPoint.getDataType().getFields()) {
Value value = dataPoint.getValue(field);
msg += field + "=" + value + ", ";
}
display.show(msg);
}
};
Fitness.SensorsApi.add(client,
new SensorRequest.Builder()
.setDataSource(dataSource)
.setDataType(dataType)
.setSamplingRate(30, TimeUnit.SECONDS)
.build(),
listener)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
if (status.isSuccess()) {
listeners.add(listener);
display.show("Listener for " + dataType.getName() + " registered");
} else {
display.show("Failed to register listener for " + dataType.getName());
}
}
});
}
}
datasourcesListener.onDatasourcesListed();
}
});
}
开发者ID:parthsatra,项目名称:WalkPotato,代码行数:56,代码来源:Sensors.java
示例12: registerDataSourceListener
import com.google.android.gms.fitness.request.SensorRequest; //导入依赖的package包/类
private void registerDataSourceListener(DataType dataType) {
onDataPointListener = new OnDataPointListener() {
@Override
public void onDataPoint(DataPoint dataPoint) {
if (dataPoint == null) {
Log.d(TAG, "registerDataSourceListener onDataPoint = " + dataPoint);
return;
}
if ( dataPoint.getDataType().equals( DataType.TYPE_STEP_COUNT_CUMULATIVE) ) {
Log.d ( TAG, " onDataPoint of type DataType.TYPE_STEP_COUNT_CUMULATIVE " ) ;
for (Field field : dataPoint.getDataType().getFields()) {
Value aValue = dataPoint.getValue(field);
Log.d(TAG, "registerDataSourceListener onDataPoint L-value= " + field.getName());
Log.d(TAG, "registerDataSourceListener onDataPoint R-value=" + aValue);
addContentToView( "dataPoint=" + field.getName() + "= " + aValue + "\n") ;
// lets write cumulative steps
if ( field.getName().equals ("steps") ) {
// ideally one should use the same datapoint and add it to the set.
// rather than :-
DataSet originatedDataSet = originateDataSetCumulativeSteps( aValue.asInt() ) ;
writeQueue.add( originatedDataSet) ;
writeFitnessHistory();
}
}
}
}
};
Fitness.SensorsApi.add(
googleApiClient,
new SensorRequest.Builder()
// .setDataSource(dataSource)
.setDataType(dataType)
.setSamplingRate(12, TimeUnit.SECONDS)
.setAccuracyMode(SensorRequest.ACCURACY_MODE_DEFAULT)
.build(),
onDataPointListener)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
if (status.isSuccess()) {
Log.d(TAG, "onDataPointListener registered good");
} else {
Log.d(TAG, "onDataPointListener failed to register bad");
}
}
});
}
开发者ID:smitzey,项目名称:wearbooksource,代码行数:58,代码来源:FitWriteHistoryActivity.java
注:本文中的com.google.android.gms.fitness.request.SensorRequest类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论