我正在使用 Google Fit Android API 来检索健身数据,这一切都像一个魅力。我还想访问当前登录用户的名称,GoogleSignInAccount .getDisplayName() 应该可以访问该名称;
我已经问过这个问题,但不幸的是没有得到任何答复,我无法通过文档弄清楚。
示例代码:
//Create a FitnessOptions instance, declaring the data types and access type (read and/or write) your app needs:
FitnessOptions fitnessOptions = FitnessOptions.builder()
.addDataType(DataType.TYPE_STEP_COUNT_DELTA, FitnessOptions.ACCESS_READ)
.addDataType(DataType.TYPE_SLEEP_SEGMENT, FitnessOptions.ACCESS_READ)
.addDataType(DataType.TYPE_HEART_RATE_BPM, FitnessOptions.ACCESS_READ)
.addDataType(DataType.AGGREGATE_HEART_RATE_SUMMARY, FitnessOptions.ACCESS_READ)
.build();
//Get an instance of the Account object to use with the API:
GoogleSignInAccount account = GoogleSignIn.getAccountForExtension(this, fitnessOptions);
GoogleSignInAccount acct = GoogleSignIn.getLastSignedInAccount(this);
if (acct != null) {
loggedInUser = account.getDisplayName();
}
问题是 acct.getDisplayname().getGrantedScopes 就像一个魅力,我看到了授予的范围。当我尝试阅读 .getDisplayName 时,我总是得到 NULL。