Himz
Himz

Reputation: 523

Upload multiple photos to facebook from android (facebook sdk 3)

I am trying to upload all photos in my sdcard folder to facebook album . I have written the following code for the same. is the list of all the image files. But, programs runs in to exception. I am not able to figure out the reason. Any inputs in this regard are welcome .

    RequestBatch requestBatch = new RequestBatch();
    for (final String requestId : fileNames) {
        Bitmap image = BitmapFactory.decodeFile(requestId);
        Request request = Request.newUploadPhotoRequest(Session.getActiveSession(), image, new Request.Callback() {
            @Override
            public void onCompleted(Response response) {
                showPublishResult("Photo Post ", response.getGraphObject(), response.getError());
            }
        });

        requestBatch.add(request);
    }
    requestBatch.executeAsync();
}

Update :

It is running into OutOfMemoryException. That means, the sdk is caching the files, and as a result this is happening . Is there any other way to achieve the same, rather than sending the bitmap image as request ?

Upvotes: 0

Views: 913

Answers (1)

Himz
Himz

Reputation: 523

The issue with above approach was executeAsync.

We need to create a new thread, make it a daemon(so that even on app exit, the upload can finish the queue), and to publish use executeAndWait. This way , all the files are serially uploaded.

If some one need the new code, Message here, i will post it

Upvotes: 1

Related Questions