task.getResult() returns false while unregistering an OnDataPointListener
/**
* Register fitness listeners for all the required data types
*/
private void registerFitnessListeners() {
mStepCountListener =
new OnDataPointListener() {
@Override
public void onDataPoint(DataPoint dataPoint) {
for (Field field : dataPoint.getDataType().getFields()){
int stepDelta = dataPoint.getValue(field).asInt();
mSteps += stepDelta;
stepCountTextView.setText(
"Detected Datapoint field: " + field.getName()
+ "nDetected Datapoint value:" + mSteps);
}
}
};
Fitness.getSensorsClient(mContext, mGoogleSignInAccount)
.add(
new SensorRequest.Builder()
.setDataType(DataType.TYPE_STEP_COUNT_DELTA)
.setSamplingRate(1, TimeUnit.SECONDS)
.setMaxDeliveryLatency(3, TimeUnit.SECONDS)
.setFastestRate(1, TimeUnit.SECONDS)
.build(),
mStepCountListener)
.addOnCompleteListener(
new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()){
Log.d(TAG, "Listener registered");
}else{
Log.e(TAG, "Listener not registered", task.getException());
}
}
});
}
/**
* Unregisters the listener with the Sensors API.
*/
private void unregisterFitnessListeners(){
Fitness.getSensorsClient(mContext, mGoogleSignInAccount)
.remove(mStepCountListener)
.addOnCompleteListener(new OnCompleteListener<Boolean>() {
@Override
public void onComplete(@NonNull Task<Boolean> task) {
if(task.isSuccessful() && task.getResult()){
Log.d(TAG, "Listener was removed");
}else{
Log.d(TAG, "Listener was not removed");
}
}
});
}
When I try to unregister a OnDataPointListener for counting steps, my LogCat always says listener was not removed. I got to know that task.getResult() is always returning false. Why is this so?? Am I doing something wrong? How can I remove the listener?
java
add a comment |
/**
* Register fitness listeners for all the required data types
*/
private void registerFitnessListeners() {
mStepCountListener =
new OnDataPointListener() {
@Override
public void onDataPoint(DataPoint dataPoint) {
for (Field field : dataPoint.getDataType().getFields()){
int stepDelta = dataPoint.getValue(field).asInt();
mSteps += stepDelta;
stepCountTextView.setText(
"Detected Datapoint field: " + field.getName()
+ "nDetected Datapoint value:" + mSteps);
}
}
};
Fitness.getSensorsClient(mContext, mGoogleSignInAccount)
.add(
new SensorRequest.Builder()
.setDataType(DataType.TYPE_STEP_COUNT_DELTA)
.setSamplingRate(1, TimeUnit.SECONDS)
.setMaxDeliveryLatency(3, TimeUnit.SECONDS)
.setFastestRate(1, TimeUnit.SECONDS)
.build(),
mStepCountListener)
.addOnCompleteListener(
new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()){
Log.d(TAG, "Listener registered");
}else{
Log.e(TAG, "Listener not registered", task.getException());
}
}
});
}
/**
* Unregisters the listener with the Sensors API.
*/
private void unregisterFitnessListeners(){
Fitness.getSensorsClient(mContext, mGoogleSignInAccount)
.remove(mStepCountListener)
.addOnCompleteListener(new OnCompleteListener<Boolean>() {
@Override
public void onComplete(@NonNull Task<Boolean> task) {
if(task.isSuccessful() && task.getResult()){
Log.d(TAG, "Listener was removed");
}else{
Log.d(TAG, "Listener was not removed");
}
}
});
}
When I try to unregister a OnDataPointListener for counting steps, my LogCat always says listener was not removed. I got to know that task.getResult() is always returning false. Why is this so?? Am I doing something wrong? How can I remove the listener?
java
i have same problem have get solutions?
– Vanraj Ghed
Jul 13 '18 at 5:51
@VanrajGhed, I figured out that the bug was only in the latest version of the google fit api. The old version works correctly. So you can change the version from the one you're using to the one below : 'com.google.android.gms:play-services-fitness:12.0.1'
– user9215061
Nov 14 '18 at 23:08
add a comment |
/**
* Register fitness listeners for all the required data types
*/
private void registerFitnessListeners() {
mStepCountListener =
new OnDataPointListener() {
@Override
public void onDataPoint(DataPoint dataPoint) {
for (Field field : dataPoint.getDataType().getFields()){
int stepDelta = dataPoint.getValue(field).asInt();
mSteps += stepDelta;
stepCountTextView.setText(
"Detected Datapoint field: " + field.getName()
+ "nDetected Datapoint value:" + mSteps);
}
}
};
Fitness.getSensorsClient(mContext, mGoogleSignInAccount)
.add(
new SensorRequest.Builder()
.setDataType(DataType.TYPE_STEP_COUNT_DELTA)
.setSamplingRate(1, TimeUnit.SECONDS)
.setMaxDeliveryLatency(3, TimeUnit.SECONDS)
.setFastestRate(1, TimeUnit.SECONDS)
.build(),
mStepCountListener)
.addOnCompleteListener(
new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()){
Log.d(TAG, "Listener registered");
}else{
Log.e(TAG, "Listener not registered", task.getException());
}
}
});
}
/**
* Unregisters the listener with the Sensors API.
*/
private void unregisterFitnessListeners(){
Fitness.getSensorsClient(mContext, mGoogleSignInAccount)
.remove(mStepCountListener)
.addOnCompleteListener(new OnCompleteListener<Boolean>() {
@Override
public void onComplete(@NonNull Task<Boolean> task) {
if(task.isSuccessful() && task.getResult()){
Log.d(TAG, "Listener was removed");
}else{
Log.d(TAG, "Listener was not removed");
}
}
});
}
When I try to unregister a OnDataPointListener for counting steps, my LogCat always says listener was not removed. I got to know that task.getResult() is always returning false. Why is this so?? Am I doing something wrong? How can I remove the listener?
java
/**
* Register fitness listeners for all the required data types
*/
private void registerFitnessListeners() {
mStepCountListener =
new OnDataPointListener() {
@Override
public void onDataPoint(DataPoint dataPoint) {
for (Field field : dataPoint.getDataType().getFields()){
int stepDelta = dataPoint.getValue(field).asInt();
mSteps += stepDelta;
stepCountTextView.setText(
"Detected Datapoint field: " + field.getName()
+ "nDetected Datapoint value:" + mSteps);
}
}
};
Fitness.getSensorsClient(mContext, mGoogleSignInAccount)
.add(
new SensorRequest.Builder()
.setDataType(DataType.TYPE_STEP_COUNT_DELTA)
.setSamplingRate(1, TimeUnit.SECONDS)
.setMaxDeliveryLatency(3, TimeUnit.SECONDS)
.setFastestRate(1, TimeUnit.SECONDS)
.build(),
mStepCountListener)
.addOnCompleteListener(
new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()){
Log.d(TAG, "Listener registered");
}else{
Log.e(TAG, "Listener not registered", task.getException());
}
}
});
}
/**
* Unregisters the listener with the Sensors API.
*/
private void unregisterFitnessListeners(){
Fitness.getSensorsClient(mContext, mGoogleSignInAccount)
.remove(mStepCountListener)
.addOnCompleteListener(new OnCompleteListener<Boolean>() {
@Override
public void onComplete(@NonNull Task<Boolean> task) {
if(task.isSuccessful() && task.getResult()){
Log.d(TAG, "Listener was removed");
}else{
Log.d(TAG, "Listener was not removed");
}
}
});
}
When I try to unregister a OnDataPointListener for counting steps, my LogCat always says listener was not removed. I got to know that task.getResult() is always returning false. Why is this so?? Am I doing something wrong? How can I remove the listener?
java
java
asked Jun 20 '18 at 16:49
user9215061user9215061
162
162
i have same problem have get solutions?
– Vanraj Ghed
Jul 13 '18 at 5:51
@VanrajGhed, I figured out that the bug was only in the latest version of the google fit api. The old version works correctly. So you can change the version from the one you're using to the one below : 'com.google.android.gms:play-services-fitness:12.0.1'
– user9215061
Nov 14 '18 at 23:08
add a comment |
i have same problem have get solutions?
– Vanraj Ghed
Jul 13 '18 at 5:51
@VanrajGhed, I figured out that the bug was only in the latest version of the google fit api. The old version works correctly. So you can change the version from the one you're using to the one below : 'com.google.android.gms:play-services-fitness:12.0.1'
– user9215061
Nov 14 '18 at 23:08
i have same problem have get solutions?
– Vanraj Ghed
Jul 13 '18 at 5:51
i have same problem have get solutions?
– Vanraj Ghed
Jul 13 '18 at 5:51
@VanrajGhed, I figured out that the bug was only in the latest version of the google fit api. The old version works correctly. So you can change the version from the one you're using to the one below : 'com.google.android.gms:play-services-fitness:12.0.1'
– user9215061
Nov 14 '18 at 23:08
@VanrajGhed, I figured out that the bug was only in the latest version of the google fit api. The old version works correctly. So you can change the version from the one you're using to the one below : 'com.google.android.gms:play-services-fitness:12.0.1'
– user9215061
Nov 14 '18 at 23:08
add a comment |
2 Answers
2
active
oldest
votes
Even I was facing a similar issue but then I tried a way around the SensorsApi
GoogleApiClient googleApiClient = Fitness
.getSensorsClient(context, GoogleSignIn.getLastSignedInAccount(context))
.asGoogleApiClient();
Fitness.SensorsApi.remove(googleApiClient, mListener).setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
if (status.isSuccess()) {
Log.d(TAG, "onResult: Successfully removed sensor api");
} else {
Log.e(TAG, "onResult: Unable to remove sensor api");
}
}
});
And it works like a charm!
thank you. I have been struggling with this for days
– FabioC
Jan 2 at 21:11
add a comment |
I figured out that the bug was only in the latest version of the google fit sdk. The old version works correctly. So changing the version to the one below worked: 'com.google.android.gms:play-services-fitness:12.0.1'
add a comment |
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%2f50953326%2ftask-getresult-returns-false-while-unregistering-an-ondatapointlistener%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Even I was facing a similar issue but then I tried a way around the SensorsApi
GoogleApiClient googleApiClient = Fitness
.getSensorsClient(context, GoogleSignIn.getLastSignedInAccount(context))
.asGoogleApiClient();
Fitness.SensorsApi.remove(googleApiClient, mListener).setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
if (status.isSuccess()) {
Log.d(TAG, "onResult: Successfully removed sensor api");
} else {
Log.e(TAG, "onResult: Unable to remove sensor api");
}
}
});
And it works like a charm!
thank you. I have been struggling with this for days
– FabioC
Jan 2 at 21:11
add a comment |
Even I was facing a similar issue but then I tried a way around the SensorsApi
GoogleApiClient googleApiClient = Fitness
.getSensorsClient(context, GoogleSignIn.getLastSignedInAccount(context))
.asGoogleApiClient();
Fitness.SensorsApi.remove(googleApiClient, mListener).setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
if (status.isSuccess()) {
Log.d(TAG, "onResult: Successfully removed sensor api");
} else {
Log.e(TAG, "onResult: Unable to remove sensor api");
}
}
});
And it works like a charm!
thank you. I have been struggling with this for days
– FabioC
Jan 2 at 21:11
add a comment |
Even I was facing a similar issue but then I tried a way around the SensorsApi
GoogleApiClient googleApiClient = Fitness
.getSensorsClient(context, GoogleSignIn.getLastSignedInAccount(context))
.asGoogleApiClient();
Fitness.SensorsApi.remove(googleApiClient, mListener).setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
if (status.isSuccess()) {
Log.d(TAG, "onResult: Successfully removed sensor api");
} else {
Log.e(TAG, "onResult: Unable to remove sensor api");
}
}
});
And it works like a charm!
Even I was facing a similar issue but then I tried a way around the SensorsApi
GoogleApiClient googleApiClient = Fitness
.getSensorsClient(context, GoogleSignIn.getLastSignedInAccount(context))
.asGoogleApiClient();
Fitness.SensorsApi.remove(googleApiClient, mListener).setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
if (status.isSuccess()) {
Log.d(TAG, "onResult: Successfully removed sensor api");
} else {
Log.e(TAG, "onResult: Unable to remove sensor api");
}
}
});
And it works like a charm!
answered Dec 29 '18 at 15:06
Abhay PaiAbhay Pai
174112
174112
thank you. I have been struggling with this for days
– FabioC
Jan 2 at 21:11
add a comment |
thank you. I have been struggling with this for days
– FabioC
Jan 2 at 21:11
thank you. I have been struggling with this for days
– FabioC
Jan 2 at 21:11
thank you. I have been struggling with this for days
– FabioC
Jan 2 at 21:11
add a comment |
I figured out that the bug was only in the latest version of the google fit sdk. The old version works correctly. So changing the version to the one below worked: 'com.google.android.gms:play-services-fitness:12.0.1'
add a comment |
I figured out that the bug was only in the latest version of the google fit sdk. The old version works correctly. So changing the version to the one below worked: 'com.google.android.gms:play-services-fitness:12.0.1'
add a comment |
I figured out that the bug was only in the latest version of the google fit sdk. The old version works correctly. So changing the version to the one below worked: 'com.google.android.gms:play-services-fitness:12.0.1'
I figured out that the bug was only in the latest version of the google fit sdk. The old version works correctly. So changing the version to the one below worked: 'com.google.android.gms:play-services-fitness:12.0.1'
answered Nov 14 '18 at 23:09
user9215061user9215061
162
162
add a comment |
add a comment |
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%2f50953326%2ftask-getresult-returns-false-while-unregistering-an-ondatapointlistener%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
i have same problem have get solutions?
– Vanraj Ghed
Jul 13 '18 at 5:51
@VanrajGhed, I figured out that the bug was only in the latest version of the google fit api. The old version works correctly. So you can change the version from the one you're using to the one below : 'com.google.android.gms:play-services-fitness:12.0.1'
– user9215061
Nov 14 '18 at 23:08