本文整理汇总了Java中com.google.android.gms.fitness.request.DataDeleteRequest类的典型用法代码示例。如果您正苦于以下问题:Java DataDeleteRequest类的具体用法?Java DataDeleteRequest怎么用?Java DataDeleteRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DataDeleteRequest类属于com.google.android.gms.fitness.request包,在下文中一共展示了DataDeleteRequest类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doInBackground
import com.google.android.gms.fitness.request.DataDeleteRequest; //导入依赖的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: deleteData
import com.google.android.gms.fitness.request.DataDeleteRequest; //导入依赖的package包/类
/**
* Delete a {@link DataSet} from the History API. In this example, we delete all
* step count data for the past 24 hours.
*/
private void deleteData() {
Log.i(TAG, "Deleting today's step count data.");
// [START delete_dataset]
// Set a start and end time for our data, using a start time of 1 day before this moment.
Calendar cal = Calendar.getInstance();
Date now = new Date();
cal.setTime(now);
long endTime = cal.getTimeInMillis();
cal.add(Calendar.DAY_OF_YEAR, -1);
long startTime = cal.getTimeInMillis();
// Create a delete request object, providing a data type and a time interval
DataDeleteRequest request = new DataDeleteRequest.Builder()
.setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS)
.addDataType(DataType.TYPE_STEP_COUNT_DELTA)
.build();
// Invoke the History API with the Google API client object and delete request, and then
// specify a callback that will check the result.
Fitness.HistoryApi.deleteData(mClient, request)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
if (status.isSuccess()) {
Log.i(TAG, "Successfully deleted today's step count data.");
} else {
// The deletion will fail if the requesting app tries to delete data
// that it did not insert.
Log.i(TAG, "Failed to delete today's step count data.");
}
}
});
// [END delete_dataset]
}
示例3: deleteSessionData
import com.google.android.gms.fitness.request.DataDeleteRequest; //导入依赖的package包/类
/**
* Deletes the {@link DataSet} we inserted with our {@link Session} from the History API.
* In this example, we delete all step count data for the past 24 hours. Note that this
* deletion uses the History API, and not the Sessions API, since sessions are truly just time
* intervals over a set of data, and the data is what we are interested in removing.
*/
private void deleteSessionData() {
Log.i(TAG, "Deleting today's session data for speed");
// Set a start and end time for our data, using a start time of 1 day before this moment.
Calendar cal = Calendar.getInstance();
Date now = new Date();
cal.setTime(now);
long endTime = cal.getTimeInMillis();
cal.add(Calendar.DAY_OF_YEAR, -1);
long startTime = cal.getTimeInMillis();
// Create a delete request object, providing a data type and a time interval
DataDeleteRequest request = new DataDeleteRequest.Builder()
.setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS)
.addDataType(DataType.TYPE_SPEED)
.deleteAllSessions() // Or specify a particular session here
.build();
// Delete request using HistoryClient and specify listeners that will check the result.
Fitness.getHistoryClient(getActivity(), GoogleSignIn.getLastSignedInAccount(getContext()))
.deleteData(request)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Log.i(TAG, "Successfully deleted today's sessions");
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
// The deletion will fail if the requesting app tries to delete data
// that it did not insert.
Log.i(TAG, "Failed to delete today's sessions");
}
});
viewSessionData();
}
示例4: deleteStepsYesterday
import com.google.android.gms.fitness.request.DataDeleteRequest; //导入依赖的package包/类
/**
* Deletes a {@link DataSet} from the History API. In this example, we delete all step count data
* for the past 24 hours.
*/
private void deleteStepsYesterday() {
Log.i(TAG, "Deleting today's session data for speed");
// Set a start and end time for our data, using a start time of 1 day before this moment.
Calendar cal = Calendar.getInstance();
Date now = new Date();
cal.setTime(now);
long endTime = cal.getTimeInMillis();
cal.add(Calendar.DAY_OF_YEAR, -1);
long startTime = cal.getTimeInMillis();
// Create a delete request object, providing a data type and a time interval
DataDeleteRequest request = new DataDeleteRequest.Builder()
.setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS)
.addDataType(DataType.TYPE_STEP_COUNT_DELTA)
.deleteAllSessions() // Or specify a particular session here
.build();
// Delete request using HistoryClient and specify listeners that will check the result.
Fitness.getHistoryClient(getActivity(), GoogleSignIn.getLastSignedInAccount(getContext()))
.deleteData(request)
.addOnCompleteListener(
new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
sendmessage( "Successfully deleted today's step count data.");
} else {
sendmessage( "Failed to delete today's step count data." + task.getException());
}
}
});
displayLastWeeksData();
}
示例5: delData
import com.google.android.gms.fitness.request.DataDeleteRequest; //导入依赖的package包/类
public void delData() {
Calendar cal = Calendar.getInstance();
Date now = new Date();
cal.setTime(now);
long endTime = cal.getTimeInMillis();
cal.add(Calendar.WEEK_OF_YEAR, -4);
long startTime = cal.getTimeInMillis();
DataDeleteRequest delRequest = new DataDeleteRequest.Builder()
.setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS)
.deleteAllData()
.deleteAllSessions()
.build();
Fitness.HistoryApi.deleteData(mClient, delRequest)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
if(status.isSuccess()) {
Log.d(LOG_TAG, "Successfully deleted sessions");
}
else {
Log.d(LOG_TAG, "Failed to delete sessions");
}
}
});
}
示例6: deleteData
import com.google.android.gms.fitness.request.DataDeleteRequest; //导入依赖的package包/类
@NonNull
public Completable deleteData(DataDeleteRequest request) {
return CompletableTask.create(() -> client.deleteData(request));
}
示例7: deleteDay
import com.google.android.gms.fitness.request.DataDeleteRequest; //导入依赖的package包/类
public void deleteDay() {
Calendar cal = Calendar.getInstance();
Date now = new Date();
cal.setTime(now);
// Set a start and end time for our data, using a start time of 1 day before this moment.
long endTime = cal.getTimeInMillis();
cal.add(Calendar.DAY_OF_YEAR, -1);
long startTime = cal.getTimeInMillis();
long syncStart = startTime - (1000 * 60 * 60 * 24);
SQLiteDatabase db = getDatabase();
if (db != null && db.isOpen()) {
cupboard().withDatabase(db).delete(Workout.class, "start >= ?", "" + syncStart);
} else {
Log.w(TAG, "Warning: db is null");
}
//closeDatabase();
// https://developers.google.com/android/reference/com/google/android/gms/fitness/request/DataDeleteRequest
// Create a delete request object, providing a data type and a time interval
DataDeleteRequest request = new DataDeleteRequest.Builder()
.setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS)
.deleteAllData()
.deleteAllSessions()
.build();
// Invoke the History API with the Google API client object and delete request, and then
// specify a callback that will check the result.
Fitness.HistoryApi.deleteData(mClient, request)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
if (status.isSuccess()) {
Log.i(TAG, "Successfully deleted last day of data.");
} else {
// The deletion will fail if the requesting app tries to delete data
// that it did not insert.
Log.i(TAG, "Failed to delete workout");
}
}
});
Context context = getApplicationContext();
if(context != null) {
UserPreferences.setLastSync(context, syncStart);
}
populateHistoricalData();
}
示例8: deleteWorkout
import com.google.android.gms.fitness.request.DataDeleteRequest; //导入依赖的package包/类
public void deleteWorkout(final Workout workout) {
if (isConnected()) {
// Set a start and end time for our data, using a start time of 1 day before this moment.
long endTime = workout.start + workout.duration;
long startTime = workout.start;
//long syncStart = workout.start - (1000 * 60 * 60 * 8);
SQLiteDatabase db = getDatabase();
if (db != null && db.isOpen()) {
//cupboard().withDatabase(db).delete(Workout.class, "start >= ?", "" + syncStart);
cupboard().withDatabase(db).delete(Workout.class, "start = ? AND type = ?", "" + startTime, "" + workout.type);
} else {
Log.w(TAG, "Warning: db is null");
}
//closeDatabase();
// https://developers.google.com/android/reference/com/google/android/gms/fitness/request/DataDeleteRequest
// Create a delete request object, providing a data type and a time interval
DataDeleteRequest request = new DataDeleteRequest.Builder()
.setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS)
.deleteAllData()
.deleteAllSessions()
.build();
// Invoke the History API with the Google API client object and delete request, and then
// specify a callback that will check the result.
Fitness.HistoryApi.deleteData(mClient, request)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
if (status.isSuccess()) {
Log.i(TAG, "Successfully deleted: " + workout.toString());
} else {
// The deletion will fail if the requesting app tries to delete data
// that it did not insert.
Log.i(TAG, "Failed to delete workout");
}
}
});
notifyListenersDataChanged(Utilities.TimeFrame.ALL_TIME);
}
}