Search code examples
androidfitbit

Android fitbit integration


Hi I followed fitbit documentation to integrate fitbit into my app. My problem is once I authenticated the application means it is not redirecting me to my andropid activity. I show my codes

button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String url = "https://www.fitbit.com/oauth2/authorize?response_type=code&client_id="
                        + cliend id + "&redirect_uri=" + redirect_uri + "&scope=" + "activity";
                Intent oauthIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                startActivity(oauthIntent);
            }
        });

in my manifest

<intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="MyExample4" />
            </intent-filter>

It is taking me to my redirect page.Can anyone come across this problem means please help me.


Solution

  • I'm not familiar with fitbit but from what I can see in your code i can say that your intent filter is not complete. You should probably make the intent filter match the redirect_uri that you embed in the authentication URL.

    Once you implement that and the user correctly authenticates the browser will navigate to redirect_uri and with the correct intent-filter you'll be able to open that in your app.

    The code could be as follows:

    Set your redirect_uri to my-fitbit-app://my.fitbit.app/handle_auth

    In your intent-filter

    <intent-filter>
                    <action android:name="android.intent.action.VIEW" />
                    <category android:name="android.intent.category.DEFAULT" />
                    <category android:name="android.intent.category.BROWSABLE" />
                    <data android:scheme="my-fitbit-app" />
                    <data android:host="my.fitbit.app" />
                    <data android:path="/handle_auth" />
                </intent-filter>