[覆盖时出现错误,如图像链接中所示。我已经在我的程序的主要活动中编写了这段代码,它在重写onsuccessListener时显示错误,当我在android设备监视器上运行整个代码时,android设备上显示的输出是 - APP已停止] [1]请有人帮助我解决这个问题。 [1]:https://i.stack.imgur.com/BztIM.jpg
private void accessGoogleFit() {
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
long endTime = cal.getTimeInMillis();
cal.add(Calendar.YEAR, -1);
long startTime = cal.getTimeInMillis();
DataReadRequest readRequest = new DataReadRequest.Builder()
.aggregate(DataType.TYPE_STEP_COUNT_DELTA, DataType.AGGREGATE_STEP_COUNT_DELTA)
.setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
.build();
Fitness.getHistoryClient(this, GoogleSignIn.getLastSignedInAccount(this))
.readData(readRequest)
.addOnSuccessListener(new OnSuccessListener() {
@Override
public void onSuccess(DataReadResponse dataReadResponse) {
Log.d(TAG, "onSuccess()");
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.e(TAG, "onFailure()", e);
}
})
.addOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(@NonNull Task task) {
Log.d(TAG, "onComplete()");
}
});
答案 0 :(得分:1)
请改为尝试:
.addOnSuccessListener(new OnSuccessListener<DataReadResponse>() {
@Override
public void onSuccess(DataReadResponse dataReadResponse) {
Log.d(TAG, "onSuccess()");
}
})