Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add callback to openFit() function #212

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
**/node_modules/**
node_modules/
node_modules/**
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ Please read https://developers.google.com/fit/improvements why we made the chang

deleteWeight(options, callback); // method to delete weights by options (same as in delete hydration)

openFit(); //method to open google fit app
openFit(callback); //method to open google fit app

saveHeight(options, callback);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public void disconnect(Context context) {
.build();
GoogleSignInClient googleSignInClient = GoogleSignIn.getClient(context, options);

GoogleSignInAccount gsa = GoogleSignIn.getAccountForScopes(mReactContext, new Scope(Scopes.FITNESS_ACTIVITY_READ));
GoogleSignInAccount gsa = GoogleSignIn.getAccountForScopes(mReactContext, new Scope("https://www.googleapis.com/auth/fitness.activity.read"));
Fitness.getConfigClient(mReactContext, gsa).disableFit();
mApiClient.disconnect();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,15 @@ public void isEnabled(Callback errorCallback, Callback successCallback) { // tru
}

@ReactMethod
public void openFit() {
public void openFit(Callback errorCallback, Callback successCallback) {
PackageManager pm = mReactContext.getPackageManager();
try {
Intent launchIntent = pm.getLaunchIntentForPackage(GOOGLE_FIT_APP_URI);
mReactContext.startActivity(launchIntent);
successCallback.invoke(true);
} catch (Exception e) {
Log.i(REACT_MODULE, e.toString());
errorCallback.invoke(true);
}
}

Expand Down
2 changes: 1 addition & 1 deletion index.android.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ declare module 'react-native-google-fit' {

isEnabled(callback: (isError: boolean, result: boolean) => void): void

openFit(): void
openFit(callback: (isError: boolean, result: boolean) => void): void

observeSteps: (callback: (isError: boolean, result: any) => void) => void

Expand Down
4 changes: 2 additions & 2 deletions index.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,8 @@ class RNGoogleFit {
)
}

openFit() {
googleFit.openFit()
openFit(callback) {
googleFit.openFit((msg) => callback(msg, false), res => callback(false,res))
}

observeSteps = callback => {
Expand Down