API Examples - Android

Android Upload Example:

Uploading to FrameSocket via Android is only a matter of correctly formulating a POST request. We've included a sample application below that involves selecting a media file, formulating an authenticated upload request to FrameSocket, and processing the response.

Download: FrameSocket_Upload_Example_Android.zip

Please make sure that you insert the correct API Key information within UploadExample.java so that your requests are not rejected.

This sample application uses the Apache HTTP Client libraries (v. 4.0.3) - which can be found here. If you decide to use this package, ensure that you download the package titled "Binary with Dependencies" and include the following within your project:

  • apache-mime4j-0.6.jar
  • httpclient-4.0.3.jar
  • httpcore-4.0.1.jar
  • httpmime-4.0.3.jar

Of particular note is the section of code that formulates the POST request, and sends that request to the FrameSocket API.

HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://www.framesocket.com/api/media/upload.php");
MultipartEntity multipartEntity = new MultipartEntity();

try {
	// Add authentication variables.
	multipartEntity.addPart("key", new StringBody(fsKey));
	multipartEntity.addPart("secret", new StringBody(fsSecret));
	multipartEntity.addPart("sig", new StringBody(md5(fsGatekeeper+"upload")));
	// Optionally add title, description, etc.
	// multipartEntity.addPart("title", new StringBody("Test Android Upload"));
	// Add the media file:
	multipartEntity.addPart("media", new InputStreamBody(getContentResolver().openInputStream(mediaUri),mediaFilename));
	// Execute POST request.
	HttpResponse httpResponse = httpClient.execute(httpPost);
	// Handle Response
	HttpEntity httpEntity = httpResponse.getEntity();
	InputStream inputStream = httpEntity.getContent();
	String resultString = convertStreamToString(inputStream);
	resultJson = new JSONObject(resultString);
	return 1;
} catch (Exception e) {

return 0;

Android Content Example:

We'll be posting more examples later on, including how to efficiently display content from FrameSocket within your App.

Have a question? We are currently: