1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Cannot resolve GOOGLE_FIT_PERMISSIONS_REQUEST_CODE

Discussion in 'Programming/Internet' started by Muhammad Ahmed, Sep 12, 2018.

  1. I am using Google Fit API in Android Studio and I was following the this tutorial, but an error occurred, saying:


    cannot resolve the symbol.

    I have searched for a solution for this, but I could not find one.

    I have also put the dependencies on my module gradle, as told in their website.


    GOOGLE_FIT_PERMISSIONS_REQUEST_CODE

    Here is the code I have copied from the above mentioned link:

    public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    FitnessOptions fitnessOptions = FitnessOptions.builder()
    .addDataType(DataType.TYPE_STEP_COUNT_DELTA, FitnessOptions.ACCESS_READ)
    .addDataType(DataType.AGGREGATE_STEP_COUNT_DELTA, FitnessOptions.ACCESS_READ)
    .build();
    if (!GoogleSignIn.hasPermissions(GoogleSignIn.getLastSignedInAccount(this), fitnessOptions)) {
    GoogleSignIn.requestPermissions(this, GOOGLE_FIT_PERMISSIONS_REQUEST_CODE, GoogleSignIn.getLastSignedInAccount(this), fitnessOptions);
    } else {

    accessGoogleFit();
    }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    if (resultCode == Activity.RESULT_OK) {
    if (requestCode == GOOGLE_FIT_PERMISSIONS_REQUEST_CODE) {
    accessGoogleFit();
    }
    }
    }
    private void accessGoogleFit() {
    final String LOG_TAG="i am here";
    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(Object o) {
    Log.d(LOG_TAG, "onSuccess()");
    }


    })
    .addOnFailureListener(new OnFailureListener() {
    @Override
    public void onFailure(@NonNull Exception e) {
    Log.e(LOG_TAG, "onFailure()", e);
    }
    })
    .addOnCompleteListener(new OnCompleteListener() {
    @Override
    public void onComplete(@NonNull Task task) {
    Log.d(LOG_TAG, "onComplete()");
    }
    });
    }
    }

    Login To add answer/comment
     

Share This Page