11

Fitbit API doesn't support webview anymore.

So, I studied chrome custom tabs and applied in my app.

But after login, when I pressed this pink button(allow button), nothing happened.(Image below)

Fitbit API Login Image

How can I receive access token and store it in app?

Please help me.

Thanks.

Itteh Kitteh
  • 437
  • 5
  • 6
Cloud
  • 125
  • 1
  • 8

2 Answers2

6

When authorizing agains the Fitbit API, you need to provide a redirect_uri, which is where the user will be taken after logging in. You need to provide a uri that will take the user back to your application.

To achieve that, create an intent filter and add a data tag with a custom scheme, such as myapplication://logincallback to the Activity you want to handle the login.

The intent filter will look something like this:

<intent-filter . . . >
    <data android:scheme="myapplication" android:host="logincallback" />
    . . .
</intent-filter>

Now, set the redirect_uri as mypplication://logincallback to the authorization step of the flow, and when the user clicks the pink button, it should open the Activity you added the intent filter.

You will be able to retrieve the parameters inside your activity by calling getData on the Intent.

andreban
  • 4,621
  • 1
  • 20
  • 49
  • 1
    Thanks a lot!! I'll try this solution tomorrow. Have a nice day! – Cloud Nov 19 '15 at 11:54
  • 1
    seems like a workaround, I need to create an extra activity just to get the code. Is there any good solution same like webviews for chrome tabs ? – Piyush Agarwal Nov 27 '15 at 12:45
  • This is not working. I have a url just for call back so a page opens with not found error and only after a reload the activity gets triggered :( – Piyush Agarwal Nov 29 '15 at 17:10
  • @Cloud I'm having the same issue. Did you figure this out? – C2H6O Jan 04 '16 at 19:08
  • @C2H6O did either of you ever figure this out? Running into this issue myself. – russjr08 Jan 18 '16 at 22:49
  • 1
    @russjr08 No, I'm not sure if it is possible. I ended up using the standard approach of implicit Intents which worked well for me. – C2H6O Jan 19 '16 at 19:25
0
<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:host="logincallback"
                android:pathPattern=".*"
                android:scheme="myapp" />
        </intent-filter>

Suppose you have redirect_uri myapp://logincallback, then add above code in your activity in Manifest xml file and it will work.

Jay
  • 674
  • 11
  • 13