1.0.2 (Dec 19, 2016)
Oct 5, 2016
May 4, 2020 (Retired)
Sweetzpot AS (SweetzpotAS)
Tomás Ruiz-López (truizlop)
Chad (Binghammer)
Alessio Nunzi (alessionunzi)
Source code
APK file

Show card


A fluent API to integrate with Strava on Android apps.


This document explains how to use StravaZpot in your Android app. For additional questions, you may want to check Strava official documentation here.


Login button

StravaZpot includes a custom view to include a login button according to Strava guidelines. To do that, you can add the following code to your XML layout:


The custom attribute type accepts two different values: orange and light (default). StravaLoginButton makes use of vector drawables in the support library. Thus, if you are targeting version prior to Android API 21, you would need to add the following code to your Activity:

static {

Login Activity

Strava uses OAuth 2.0 to authenticate users, and then request them to grant permission to your app. To get a Client ID and Secret from Strava for your app, follow this link.

Once you have your app credentials, you can get an Intent to launch the login activity for your app. You can easily do it with:

Intent intent = StravaLogin.withContext(this)
startActivityForResult(intent, RQ_LOGIN);

You need to notice several things with this call:

  • <YOUR_CLIENT_ID> must be replaced with the Client ID provided by Strava when you registered your application.
  • <YOUR_REDIRECT_URL> must be in the domain you specified when you registered your app in Strava.
  • Refer to ApprovalPrompt enum to get more options for this parameter.
  • Refer to AccessScope enum to get more options for this parameter.
  • You need to launch the intent with startActivityForResult since the login activity will return a value that you will need later to obtain a token. If login to Strava was successful and the user granted permission to your app, you will receive a code that you can retrieve with:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if(requestCode == RQ_LOGIN && resultCode == RESULT_OK && data != null) {
        String code = data.getStringExtra(StravaLoginActivity.RESULT_CODE);
        // Use code to obtain token

Finally, you need to add the login activity to your manifest:

    android:label="@string/login_strava" />

Obtain a Token

Every Strava API call needs a token to prove the user is authenticated and the app has permission to access the API. After you have obtained the code from user login, you need to exchange it with Strava to get a token. You can do it with the following code:

AuthenticationConfig config = AuthenticationConfig.create()
AuthenticationAPI api = new AuthenticationAPI(config);
LoginResult result = api.getTokenForApp(AppCredentials.with(CLIENT_ID, CLIENT_SECRET))

Notice that in this call you must provide the Client ID and Secret provided by Strava when you registered your application, and the code obtained during the login process. Also, the execution of the previous code involves a network request; you are responsible for calling this code in a suitable thread, outside the UI thread. Otherwise, you will get an exception.

If the previous request is successful, you will get a LoginResult, which has a Token that you can use in your subsequent API calls, and an Athlete instance, representing the authenticated user.


AuthenticationAPI api = new AuthenticationAPI(config);

Athlete API


Before introducing the Athlete API, we have to talk about StravaConfig. StravaConfig is a class required by all the APIs in StravaZpot to configure the way it is going to interact with Strava. You can create a single instance of StravaConfig as soon as you obtain a token, and reuse it during your app lifecycle. To create an instance of StravaConfig:

StravaConfig config = StravaConfig.withToken(TOKEN)

You must provide the token obtained during the authentication process. The call to debug() method will show in the Android Monitor what is going on when you do the network requests.

Once you have the configuration object, you can proceed to use all the APIs.

Create the Athlete API object

AthleteAPI athleteAPI = new AthleteAPI(config);

Retrieve current athlete

Athlete athlete = athleteAPI.retrieveCurrentAthlete()

Retrieve another athlete

Athlete athlete = athleteAPI.retrieveAthlete(ATHLETE_ID)

Update an athlete

Athlete athlete = athleteAPI.updateAthlete()

Retrieve athlete's zones

Zones zones = athleteAPI.getAthleteZones()

Retrieve athlete's totals and stats

Stats stats = athleteAPI.getAthleteTotalsAndStats(ATHLETE_ID)

List athlete K/QOMs/CRs

List<SegmentEffort> koms = athleteAPI.listAthleteKOMS(ATHLETE_ID)

Friend API

Create the Friend API object

FriendAPI friendAPI = new FriendAPI(config);

List user's friends

List<Athlete> friends = friendAPI.getMyFriends()

List another athlete's friends

List<Athlete> friends = friendAPI.getAthleteFriends(ATHLETE_ID)

List user's followers

List<Athlete> followers = friendAPI.getMyFollowers()

List another athlete's followers

List<Athlete> followers = friendAPI.getAthleteFollowers(123456)

List common following athletes between two users

List<Athlete> followers = friendAPI.getBothFollowing(ATHLETE_ID)

Activity API

Create the Activity API object

ActivityAPI activityAPI = new ActivityAPI(config);

Create an activity

Activity activity = activityAPI.createActivity(ACTIVITY_NAME)

Retrieve an activity

Activity activity = activityAPI.getActivity(ACTIVITY_ID)

Update an activity

Activity activity = activityAPI.updateActivity(ACTIVITY_ID)

Delete an activity


List user's activities

List<Activity> activities = activityAPI.listMyActivities()

List user's friends' activities

List<Activity> activities = activityAPI.listFriendActivities()

List related activities

List<Activity> activities = activityAPI.listRelatedActivities(ACTIVITY_ID)

List activity zones

List<ActivityZone> activityZones = activityAPI.listActivityZones(ACTIVITY_ID)

List activity laps

List<ActivityLap> laps = activityAPI.listActivityLaps(ACTIVITY_ID)

Comment API

Create the Comment API object

CommentAPI commentAPI = new CommentAPI(config);

List activity comments

List<Comment> comments = commentAPI.listActivityComments(ACTIVITY_ID)

Kudos API

Create the Kudos API object

KudosAPI kudosAPI = new KudosAPI(config);

List activity kudoers

List<Athlete> athletes = kudosAPI.listActivityKudoers(ACTIVITY_ID)

Photo API

Create the Photo API object

PhotoAPI photoAPI = new PhotoAPI(config);

List activity photos

List<Photo> photos = photoAPI.listAcivityPhotos(ACTIVITY_ID)

Club API

Create the Club API object

ClubAPI clubAPI = new ClubAPI(config);

Retrieve a club

Club club = clubAPI.getClub(CLUB_ID)

List club announcements

List<Announcement> announcements = clubAPI.listClubAnnouncements(CLUB_ID)

List club group events

List<Event> events = clubAPI.listClubGroupEvents(CLUB_ID)

List user's clubs

List<Club> clubs = clubAPI.listMyClubs()

List club members

List<Athlete> athletes = clubAPI.listClubMembers(CLUB_ID)

List club admins

List<Athlete> athletes = clubAPI.listClubAdmins(CLUB_ID)

List club activities

List<Activity> activities = clubAPI.listClubActivities(CLUB_ID)

Join a club

JoinResult joinResult = clubAPI.joinClub(123456)

Leave a club

LeaveResult leaveResult = clubAPI.leaveClub(123456)

Gear API

Create the Gear API object

GearAPI gearAPI = new GearAPI(config);

Retrieve gear

Gear gear = gearAPI.getGear(GEAR_ID)

Route API

Create the Route API

RouteAPI routeAPI = new RouteAPI(config);

Retrieve a route

Route route = routeAPI.getRoute(ROUTE_ID)

List athlete's routes

List<Route> routes = routeAPI.listRoutes(ATHLETE_ID)

Segment API

Create the Segment API object

SegmentAPI segmentAPI = new SegmentAPI(config);

Retrieve a segment

Segment segment = segmentAPI.getSegment(SEGMENT_ID)

List user's starred segments

List<Segment> segments = segmentAPI.listMyStarredSegments()

List another athlete's starred segments

List<Segment> segments = segmentAPI.listStarredSegmentsByAthlete(ATHLETE_ID)

Star a segment

Segment segment = segmentAPI.starSegment(SEGMENT_ID)

Unstar a segment

Segment segment = segmentAPI.unstarSegment(SEGMENT_ID)

List segment efforts

List<SegmentEffort> efforts = segmentAPI.listSegmentEfforts(SEGMENT_ID)

Retrieve segment leaderboard

Leaderboard leaderboard = segmentAPI.getLeaderboardForSegment(SEGMENT_ID)

Explore segments

List<Segment> segments = segmentAPI.exploreSegmentsInRegion(Bounds.with(, SW_LONG),, NE_LONG)))

Segment Effort API

Create the Segment Effort API object

SegmentEffortAPI segmentEffortAPI = new SegmentEffortAPI(config);

Retrieve a segment effort

SegmentEffort segmentEffort = segmentEffortAPI.getSegmentEffort(SEGMENT_EFFORT_ID)

Stream API

Create the Stream API object

StreamAPI streamAPI = new StreamAPI(config);

Retrieve activity streams

List<Stream> streams = streamAPI.getActivityStreams(ACTIVITY_ID)
                                .forTypes(StreamType.LATLNG, StreamType.DISTANCE)

Retrieve segment effort streams

List<Stream> streams = streamAPI.getSegmentEffortStreams(SEGMENT_EFFORT_ID)
                                .forTypes(StreamType.LATLNG, StreamType.DISTANCE)

Retrieve segment streams

List<Stream> streams = streamAPI.getSegmentStreams(SEGMENT_ID)
                                .forTypes(StreamType.LATLNG, StreamType.DISTANCE)

Retrieve route streams

List<Stream> streams = streamAPI.getRouteStreams(ROUTE_ID)

Upload API

Create the Upload API object

UploadAPI uploadAPI = new UploadAPI(config);

Upload a file

Strava allows you to upload files with formats GPX, FIT or TCX. We recommend to use TCXZpot in order to generate TCX files that can be uploaded to Strava.

UploadStatus uploadStatus = uploadAPI.uploadFile(new File(<path_to_file>))
                                     .withName("A complete ride around the city")
                                     .withDescription("No description")

Check upload status

UploadStatus uploadStatus = uploadAPI.checkUploadStatus(16486788)


All the APIs in StravaZpot perform network requests in a synchronous manner and without switching to a new thread. Therefore, it is up to the user of the library to invoke the API in a suitable thread, and outside the Android UI thread in order to avoid NetworkOnMainThreadException.


StravaZpot methods do not have any checked exceptions, but users of the library should be prepared for them to happen. In particular, the following scenarios can arise:

  • Strava may return a 401 Unauthorized response code. In that case, the network request will throw a StravaUnauthorizedException. It is up to the user of the library to reuthenticate with Strava to get a new token and retry the request.
  • If any other network error happen, or the request is not successful, it will throw a StravaAPIException.


You can get StravaZpot from JCenter using Gradle. Just add this line to your build file:

compile 'com.sweetzpot.stravazpot:lib:1.3.1'


Copyright 2018 SweetZpot AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.