Read user's steps count and other fitness data from sensors without google login
I am working on an application where I want to read user's step count as well as other fitness related information like heart rate (when connected to a smart band) from both mobile sensors as well as any other fitness devices supported by Google Fit SDK.
I am trying to use Google's Fit SDK for android and trying to access the data through Sensor API but every time the code is executed I get an error: "SIGN IN REQUIRED". I don't want the user to sign in to a particular google account. I have my own login system. I also don't want to store the data in fitness store as I have my own back-end. All I want is to access the data from sensors.
Here is the dummy code which I tried:
private GoogleApiClient googleApiClient;
private static final int REQUEST_OAUTH = 1001;
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.navigation_home:
mTextMessage.setText(R.string.title_home);
return true;
case R.id.navigation_dashboard:
mTextMessage.setText(R.string.title_dashboard);
return true;
case R.id.navigation_notifications:
mTextMessage.setText(R.string.title_notifications);
return true;
}
return false;
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
mTextMessage = (TextView) findViewById(R.id.message);
BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
googleApiClient = new GoogleApiClient.Builder(this)
.addApi(Fitness.SENSORS_API)
.addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ))
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
googleApiClient.connect();
PendingResult<Status> pendingResult = Fitness.SensorsApi.add(
googleApiClient,
new SensorRequest.Builder()
.setDataType(DataType.TYPE_STEP_COUNT_DELTA)
.setSamplingRate(1, TimeUnit.MINUTES) // sample once per minute
.build(),
new OnDataPointListener() {
@Override
public void onDataPoint(DataPoint dataPoint) {
Log.e("Data Point", dataPoint.toString());
}
});
}
@Override
public void onConnected(@Nullable Bundle bundle) {
}
@Override
public void onConnectionSuspended(int i) {
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
if (requestCode == REQUEST_OAUTH && resultCode == RESULT_OK) {
googleApiClient.connect();
}
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
if (connectionResult.getErrorCode() == FitnessStatusCodes.NEEDS_OAUTH_PERMISSIONS) {
try {
connectionResult.startResolutionForResult(this, REQUEST_OAUTH);
} catch (IntentSender.SendIntentException e) {
}
}
}
Is it possible to achieve this through fitness sdk without login and if not what is the other alternative to access this information in Android.
I read somewhere that I can use sensor manager but I guess with it I have to make all the calculations myself like removing bad data points received from sensor due to sudden jerk etc which I think fitness-sdk is already doing.
android android-sensors google-api-client google-fit google-fit-sdk
add a comment |
I am working on an application where I want to read user's step count as well as other fitness related information like heart rate (when connected to a smart band) from both mobile sensors as well as any other fitness devices supported by Google Fit SDK.
I am trying to use Google's Fit SDK for android and trying to access the data through Sensor API but every time the code is executed I get an error: "SIGN IN REQUIRED". I don't want the user to sign in to a particular google account. I have my own login system. I also don't want to store the data in fitness store as I have my own back-end. All I want is to access the data from sensors.
Here is the dummy code which I tried:
private GoogleApiClient googleApiClient;
private static final int REQUEST_OAUTH = 1001;
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.navigation_home:
mTextMessage.setText(R.string.title_home);
return true;
case R.id.navigation_dashboard:
mTextMessage.setText(R.string.title_dashboard);
return true;
case R.id.navigation_notifications:
mTextMessage.setText(R.string.title_notifications);
return true;
}
return false;
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
mTextMessage = (TextView) findViewById(R.id.message);
BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
googleApiClient = new GoogleApiClient.Builder(this)
.addApi(Fitness.SENSORS_API)
.addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ))
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
googleApiClient.connect();
PendingResult<Status> pendingResult = Fitness.SensorsApi.add(
googleApiClient,
new SensorRequest.Builder()
.setDataType(DataType.TYPE_STEP_COUNT_DELTA)
.setSamplingRate(1, TimeUnit.MINUTES) // sample once per minute
.build(),
new OnDataPointListener() {
@Override
public void onDataPoint(DataPoint dataPoint) {
Log.e("Data Point", dataPoint.toString());
}
});
}
@Override
public void onConnected(@Nullable Bundle bundle) {
}
@Override
public void onConnectionSuspended(int i) {
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
if (requestCode == REQUEST_OAUTH && resultCode == RESULT_OK) {
googleApiClient.connect();
}
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
if (connectionResult.getErrorCode() == FitnessStatusCodes.NEEDS_OAUTH_PERMISSIONS) {
try {
connectionResult.startResolutionForResult(this, REQUEST_OAUTH);
} catch (IntentSender.SendIntentException e) {
}
}
}
Is it possible to achieve this through fitness sdk without login and if not what is the other alternative to access this information in Android.
I read somewhere that I can use sensor manager but I guess with it I have to make all the calculations myself like removing bad data points received from sensor due to sudden jerk etc which I think fitness-sdk is already doing.
android android-sensors google-api-client google-fit google-fit-sdk
add a comment |
I am working on an application where I want to read user's step count as well as other fitness related information like heart rate (when connected to a smart band) from both mobile sensors as well as any other fitness devices supported by Google Fit SDK.
I am trying to use Google's Fit SDK for android and trying to access the data through Sensor API but every time the code is executed I get an error: "SIGN IN REQUIRED". I don't want the user to sign in to a particular google account. I have my own login system. I also don't want to store the data in fitness store as I have my own back-end. All I want is to access the data from sensors.
Here is the dummy code which I tried:
private GoogleApiClient googleApiClient;
private static final int REQUEST_OAUTH = 1001;
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.navigation_home:
mTextMessage.setText(R.string.title_home);
return true;
case R.id.navigation_dashboard:
mTextMessage.setText(R.string.title_dashboard);
return true;
case R.id.navigation_notifications:
mTextMessage.setText(R.string.title_notifications);
return true;
}
return false;
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
mTextMessage = (TextView) findViewById(R.id.message);
BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
googleApiClient = new GoogleApiClient.Builder(this)
.addApi(Fitness.SENSORS_API)
.addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ))
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
googleApiClient.connect();
PendingResult<Status> pendingResult = Fitness.SensorsApi.add(
googleApiClient,
new SensorRequest.Builder()
.setDataType(DataType.TYPE_STEP_COUNT_DELTA)
.setSamplingRate(1, TimeUnit.MINUTES) // sample once per minute
.build(),
new OnDataPointListener() {
@Override
public void onDataPoint(DataPoint dataPoint) {
Log.e("Data Point", dataPoint.toString());
}
});
}
@Override
public void onConnected(@Nullable Bundle bundle) {
}
@Override
public void onConnectionSuspended(int i) {
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
if (requestCode == REQUEST_OAUTH && resultCode == RESULT_OK) {
googleApiClient.connect();
}
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
if (connectionResult.getErrorCode() == FitnessStatusCodes.NEEDS_OAUTH_PERMISSIONS) {
try {
connectionResult.startResolutionForResult(this, REQUEST_OAUTH);
} catch (IntentSender.SendIntentException e) {
}
}
}
Is it possible to achieve this through fitness sdk without login and if not what is the other alternative to access this information in Android.
I read somewhere that I can use sensor manager but I guess with it I have to make all the calculations myself like removing bad data points received from sensor due to sudden jerk etc which I think fitness-sdk is already doing.
android android-sensors google-api-client google-fit google-fit-sdk
I am working on an application where I want to read user's step count as well as other fitness related information like heart rate (when connected to a smart band) from both mobile sensors as well as any other fitness devices supported by Google Fit SDK.
I am trying to use Google's Fit SDK for android and trying to access the data through Sensor API but every time the code is executed I get an error: "SIGN IN REQUIRED". I don't want the user to sign in to a particular google account. I have my own login system. I also don't want to store the data in fitness store as I have my own back-end. All I want is to access the data from sensors.
Here is the dummy code which I tried:
private GoogleApiClient googleApiClient;
private static final int REQUEST_OAUTH = 1001;
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.navigation_home:
mTextMessage.setText(R.string.title_home);
return true;
case R.id.navigation_dashboard:
mTextMessage.setText(R.string.title_dashboard);
return true;
case R.id.navigation_notifications:
mTextMessage.setText(R.string.title_notifications);
return true;
}
return false;
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
mTextMessage = (TextView) findViewById(R.id.message);
BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
googleApiClient = new GoogleApiClient.Builder(this)
.addApi(Fitness.SENSORS_API)
.addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ))
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
googleApiClient.connect();
PendingResult<Status> pendingResult = Fitness.SensorsApi.add(
googleApiClient,
new SensorRequest.Builder()
.setDataType(DataType.TYPE_STEP_COUNT_DELTA)
.setSamplingRate(1, TimeUnit.MINUTES) // sample once per minute
.build(),
new OnDataPointListener() {
@Override
public void onDataPoint(DataPoint dataPoint) {
Log.e("Data Point", dataPoint.toString());
}
});
}
@Override
public void onConnected(@Nullable Bundle bundle) {
}
@Override
public void onConnectionSuspended(int i) {
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
if (requestCode == REQUEST_OAUTH && resultCode == RESULT_OK) {
googleApiClient.connect();
}
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
if (connectionResult.getErrorCode() == FitnessStatusCodes.NEEDS_OAUTH_PERMISSIONS) {
try {
connectionResult.startResolutionForResult(this, REQUEST_OAUTH);
} catch (IntentSender.SendIntentException e) {
}
}
}
Is it possible to achieve this through fitness sdk without login and if not what is the other alternative to access this information in Android.
I read somewhere that I can use sensor manager but I guess with it I have to make all the calculations myself like removing bad data points received from sensor due to sudden jerk etc which I think fitness-sdk is already doing.
android android-sensors google-api-client google-fit google-fit-sdk
android android-sensors google-api-client google-fit google-fit-sdk
edited Dec 28 '18 at 12:56
Tamir Abutbul
485214
485214
asked Dec 28 '18 at 12:52
prolificprolific
175115
175115
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53958911%2fread-users-steps-count-and-other-fitness-data-from-sensors-without-google-login%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53958911%2fread-users-steps-count-and-other-fitness-data-from-sensors-without-google-login%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown