aekanman / sleep-history Goto Github PK
View Code? Open in Web Editor NEW:sleeping:Android app to read/write sleep data on Google Fitness API
License: Apache License 2.0
:sleeping:Android app to read/write sleep data on Google Fitness API
License: Apache License 2.0
Hello Aekanman,
Below is my function to get sleep data but its not provide sleep even i have added in google fit.
Thanks in advance
private void readSleepSessions() {
Calendar cal = Calendar.getInstance();
Date now = new Date();
cal.setTime(now);
long endTime = cal.getTimeInMillis();
// cal.add(Calendar.WEEK_OF_YEAR, -1);
cal.add(Calendar.DAY_OF_MONTH, -1);
long startTime = cal.getTimeInMillis();
DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(requireContext());
Log.i(TAG, "SLEEP Range Start: " + dateFormat.format(startTime));
Log.i(TAG, "SLEEP Range End: " + dateFormat.format(endTime));
SessionReadRequest request = new SessionReadRequest.Builder()
.readSessionsFromAllApps()
.includeSleepSessions()
// Sleep segment data is required for details of the fine-granularity sleep, if it is present.
.read(DataType.TYPE_SLEEP_SEGMENT)
.setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS)
.build();
Fitness.getSessionsClient(requireContext(),getGoogleSigningAccount())
.readSession(request)
.addOnSuccessListener(new OnSuccessListener<SessionReadResponse>() {
@Override
public void onSuccess(SessionReadResponse sessionReadResponse) {
for (int i = 0; i < sessionReadResponse.getSessions().size(); i++) {
Session session = sessionReadResponse.getSessions().get(i);
// If the sleep session has finer granularity sub-components, extract them:
List<DataSet> dataSets = sessionReadResponse.getDataSet(session);
for (int j = 0; j < dataSets.size(); j++) {
DataSet mDataSet = dataSets.get(j);
for (DataPoint point : mDataSet.getDataPoints()) {
String sleepStageVal = "" + point.getValue(Field.FIELD_SLEEP_SEGMENT_TYPE).asInt();
long segmentStart = point.getStartTime(TimeUnit.MILLISECONDS);
long segmentEnd = point.getEndTime(TimeUnit.MILLISECONDS);
Log.i(TAG, "\t* Type $sleepStage between $segmentStart and $segmentEnd" + segmentStart + "" + segmentEnd);
}
}
}
}
});
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.