Upload photo to Facebook with Facebook Android SDK in Android

Just posted here the simple way to upload a photo:

android facebook publish photo

Code:

byte[] data = null;

Bitmap bi = BitmapFactory.decodeFile(photoToPost);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
data = baos.toByteArray();

Bundle params = new Bundle();
params.putString("method", "photos.upload");
params.putByteArray("picture", data);

AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
mAsyncRunner.request(null, params, "POST", new SampleUploadListener(), null);

Leave a Comment