After calling the fitbit authorize api and after the user allows the permission the application closes and again I have to start the application to open the activity which i have provided as the redirect_uri, so is there any workaround that it directly goes into the activity without the application getting closed..
Best Answer
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
@Saket89 wrote:
After calling the fitbit authorize api and after the user allows the permission the application closes and again I have to start the application to open the activity which i have provided as the redirect_uri, so is there any workaround that it directly goes into the activity without the application getting closed..
Which application—yours?
Its an health application called alivemeter in which I need to integrate fitbit but after granting the permission from the user the application closes..
below is the code that I have written to get the access token
private static class NavigationCallback extends CustomTabsCallback {
@Override
public void onNavigationEvent(int navigationEvent, Bundle extras) {
// extras.getString("access")
Log.w("FITBIT", "onNavigationEvent: Code = " + navigationEvent);
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(getSession());
customTabsIntent = builder.build();
String url = "https://www.fitbit.com/oauth2/authorize?" +
"response_type=token" +
"&client_id=******" +
"&scope=activity"+
"&redirect_uri=fitbitdemo://alivemeter";
customTabsIntent.launchUrl(MainActivity.this, Uri.parse(url));
}
private CustomTabsSession getSession() {
if (mClient == null) {
mCustomTabsSession = null;
} else if (mCustomTabsSession == null) {
mCustomTabsSession = mClient.newSession(new NavigationCallback());
}
return mCustomTabsSession;
}
I have the same problem in a real device.
When I use the emulator (Android Studio with Genymotion without Chrome) it works.
But, when I use a real device with Chrome and Custom Tabs it doesn't work. When the app is installed for first, it works and I save the (client) token in my sharedpreferences. But if I delete the sharedpreferences and I try to reconnect to Fitbit, the Chrome Custom Tab is opened and closed and I have to open manually again my app
Best Answer