Skip to Content
Technical Articles

Sprint RESTs on Android!

This blog  demonstrates how to create a bread and butter(no fancy UI!) android application to create activities in 12Sprint. The blog  would also discuss how to call RESTful services from an Android application.
Android comes with Apache Http Client api and we would use this api to make the rest service calls.
To create an activity  URL : (POST) /v1/activities <[ |]> is used 0.1.
To get all the activities created by the user  : (GET) /v1/activities <[ |]> is used.

Dealing with authentication specific stuff:

Since 12Sprints requires the user to be authenticated before he/she can play around with the activities we need to set the credentials for our user:

I managed to do this in the following manner with the android api:

DefaultHttpClient httpClient=new DefaultHttpClient();

UsernamePasswordCredentials cred=new UsernamePasswordCredentials(““, “password”); //supply your 12Sprints id here

httpClient.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), cred);

Next lets see how to fire a post request to create an activity: String activityNameTxt=activityName.getText().toString();   //get the name of the activity that the user entered

+String newActivity = ”

</p><p>+ +“<activity name=\””activityNameTxt“\”></activity>”;

byte[] newActivityByteArray = newActivity.getBytes(Encoding.UTF_8.toString());

+ByteArrayEntity reqEntity = new ByteArrayEntity(newActivityByteArray);  +



Finally execute the request:

HttpResponse res = httpClient.execute(req);

The response code can be fetched using:

int code = res.getStatusLine().getStatusCode();

and the response content using


This is how the final app for creating activity looked on the Android emulator:

The first screen of the application.

Enter activity name and click add.


You must be Logged on to comment or reply to a post.