mardi 31 mars 2015

Unable to publish picture to facebook from android app

I've write this code for share a screenshot of current view on user facebook account. This is how i take screenshot



private File captureScreen() {

Bitmap screenshot = null;
try {

if (view != null) {

screenshot = Bitmap.createBitmap(view.getMeasuredWidth(),
view.getMeasuredHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(screenshot);
view.draw(canvas);
// save pics
File cache_dir = Environment.getExternalStorageDirectory();
Log.i("SCREEN", "cache dir:" + cache_dir);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
screenshot.compress(Bitmap.CompressFormat.PNG, 90, bytes);
File f = new File(cache_dir + File.separator + "screen.png");
f.createNewFile();
FileOutputStream fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
fo.close();
return f;
}

} catch (Exception e) {
// TODO
}

return null;
}


and this is how i share screenshot



BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap bitmap = BitmapFactory.decodeFile(captureScreen()
.getAbsolutePath(), options);
if (bitmap != null) {
Request uploadRequest = Request.newUploadPhotoRequest(
Session.getActiveSession(), bitmap,
new Request.Callback() {
@Override
public void onCompleted(Response response) {
Toast.makeText(getActivity(),
"Photo uploaded successfully",
Toast.LENGTH_LONG).show();
}
});
uploadRequest.executeAsync();


Now toast of success is showed, but no picture is uploaded to my facebook profile. (my app is not public yet on facebook, but i am the owner, so i can perform all actions)


Aucun commentaire:

Enregistrer un commentaire