Share image from Android app to facebook , with Facebook SDK - android

I'm looking for (working) solution of sharing image issue.
I use Facebook SDK and everything is working fine in sharing except of putting image in parameters.
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmCanvas.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
parameters.putParcelable("picture",bmCanvas);
parameters.putString("name", "caption");
parameters.putString("description", "description");
parameters.putString("caption", "caption");
fb.dialog(CanvasActivity.this, "feed",parameters,new DialogListener(){ ....
i was trying with all of the options, i mean putting a picture parameter with uri, but also doesn't work.
The diallog with post on facebook is apearing but the image content is not loaded, and when i accept publishing the post, it's published but without photo.
Can anyone help me?
Or there is somebody who succesfully posted image from android internal or external storage to wall on facebook?

try using parameters.putByteArray("picture", bmCanvas);
instead of parameters.putParcelable("picture",bmCanvas);

Related

Share Image and Text to Facebook on android

What is the correct way to share an image and text to Facebook in android?
e.g. picture with pre-populated text.
I realise that this is not possible from the native Android share intent as described here. As it can only take an image or a link not both.
Also I have tried using the facebook-sdk-3.14 with:
FacebookDialog.ShareDialogBuilder
but I now realise this is for sharing links only.
I have also tried with:
createShareDialogBuilderForPhoto()
but this is for sharing images only.
Is there something I am missing in the sdk? I am guessing it is not possible from FacebookDialog?
Will I need to go the route of creating my own app in facebook and my own open graph action? Ideally I am looking to not have a login button.
I have also seen similar questions but most are about the share intent or if it is the sdk it at least a year out of date and the solution is some thing similar to this:
Bundle parameters = new Bundle();
parameters.putString("message", category_item_name_desc.getText().toString());
parameters.putString("picture", categoryItemsModel.getImageUrl());
parameters.putString("caption", txtDescription_desc.getText().toString());
facebook.request("/me/feed", parameters, "POST");
Tried it through the Feed Dialog (WebDialog) but im getting a "error (#324) requires upload file", Any help would be great.
You can share your image on facebook, Twitter, and Gmail:
Bitmap b =BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher);
Intent share = new Intent(Intent.ACTION_SEND);
share.setType(“image/jpeg”);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
b.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = MediaStore.Images.Media.insertImage(getContentResolver(), b, “Title”, null);
Uri imageUri = Uri.parse(path);
share.putExtra(Intent.EXTRA_STREAM, imageUri);
startActivity(Intent.createChooser(share, “Select”));
Was able to do this my self with the current Facebook SDK (3.14.1 at the time) with no login and I made it into a share intent for adding to the chooser list.
I have a demo project at https://github.com/b099l3/FacebookImageShareIntent only dependency is the facebook sdk and it is contained in one activity.
Please take a look a look on my library: https://github.com/antonkrasov/AndroidSocialNetworks
With help of it, posting is really easy:
mSocialNetworkManager.getFacebookSocialNetwork().postMessage(String message)
mSocialNetworkManager.getFacebookSocialNetwork().postPhoto(File path...)

display image from resource folder on facebook wall in android

I am trying to post an image from my Resource folder onto facebook wall. everything is working perfectly. If i use a URL of an image, it gets posted on my facebook wall. What i want to know is how do i ost an image from my resource folder to facebook wall. here is a snippet of my code. any help will be greatly appreciated.
Bundle params = new Bundle();
Context ctx = null;
#SuppressWarnings("null")
Bitmap bitmap = BitmapFactory.decodeResource(ctx.getResources(),R.drawable.bestbuy_deal);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] bitMapData = stream.toByteArray();
params.putString("name","ICE App");
params.putString("caption", "Bestbuy Deal for SONY Action Cam");
params.putString("description", "Checkout SONY ICE For exciting deals!!");
params.putString("link", "http://www.sony.com");
params.putByteArray("picture", bitMapData);
// params.putString("picture", "R.drawable.sony");
facebook.dialog(this, "me/feed",params, new DialogListener()
According to the Facebook API docs, the "picture" parameter must be a URL to the picture, not an array of bytes. I imagine this is because the facebook dialog is using a WebView to display the feed post, and the image must therefore be available on the web.
You could try using a local resource URI, but this may not work completely since the Facebook API will need to be smart enough to pull that data from the local URI and put it up on their own servers. I'd be keen to know if it works, though!

upload a bitmap to facebook from android app

I spent the past few days looking thru almost every SO question about uploading an image to Facebook, and I still can't get it to work. This is what I've done so far:
1. Created an app on facebook and got the app id
2. dl'd the facebook sdk, along with the Example code they supply there (for the SampleUploadListener)
3. Added everything to the project, and used the code given in
Android - Upload photo to Facebook with Facebook Android SDK :
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);
This doens't seem to work. The code compiles and everything runs, but no facebook popup appears and nothing gets posted in Facebook - the app just runs right through it.
Any suggestions?
According to my knowledge you are right all the way, except for the "null" you have provided for the graph path in the request method.
YOu should provide a value for graph path. Eg:"me/photos". Try this,
mAsyncRunner.request("me/photos", params, "POST", new SampleUploadListener(), null);
replace null with "me/photos" and check. It should work fine if this is the only problem with your code.
All the best.

Android phonegap app : unable to retrieve an image taken by the camera using my own code (not phonegap's)

Note- even though im using phonegap, the question is not about some issue in that.
Hi, im developing a android app. my app is using phonegap 1.3.
mi problem...
Im using phonegap apis to take a picture and display it in my app. But whats happening is due to some reason the os kills my app after the camera is launched, so that after the photo is clicked, my app is relaunched and it doesnt get the info abt the taken picture.
As a workaround to this problem (the problem), i designed a phonegap plugin which on app start checks if the app had crashed while taking a picture (some flags in code), and if it is restarting after crash, it retrieves the Pic.jpg taken by the camera and tries to displays it. The problem is that its not able to get the right image, or even a proper .jpg file for that matter.
mi code...
Phonegap makes an intent to start the camera and passes the uri for the Pic.jpg that it creates into that intent which it passes to startActivityForResult.
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
File photo = new File(DirectoryManager.getTempDirectoryPath(ctx), "Pic.jpg");
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
this.imageUri = Uri.fromFile(photo);
this.ctx.startActivityForResult((Plugin) this, intent, 0);
Note- The above code is from the file CameraLauncher.java of Phonegap.
Now, im assuming that the startActivityForResult stores the picture the user captures at the file which was created by 'photo' in the above code. So even if after the os closes the app while the camera is open (refer - the problem) the photo will be stored there. PLEASE correct me if this assumption is wrong, or if the photo might be being saved somewhere else.
So taking into account this assumption i wrote a plugin which retrieves this image using the same logic which Phonegap uses in CameraLauncher.java
Uri imageUri;
ExifHelper exif = new ExifHelper();
exif.createInFile(getTempDirectoryPath(ctx) + "/Pic.jpg");
exif.readExifData();
File photo = new File(getTempDirectoryPath(ctx), "Pic.jpg");
imageUri = Uri.fromFile(photo);
Bitmap bitmap = null;
bitmap = android.provider.MediaStore.Images.Media.getBitmap(this.ctx.getContentResolver(), imageUri);
ContentValues values = new ContentValues();
values.put(android.provider.MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
Uri uri = null;
try {
uri = this.ctx.getContentResolver().insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
} catch (UnsupportedOperationException e) {
uri = this.ctx.getContentResolver().insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values);
}
// Add compressed version of captured image to returned media store Uri
OutputStream os = this.ctx.getContentResolver().openOutputStream(uri);
bitmap.compress(Bitmap.CompressFormat.JPEG, 20, os);
os.close();
exif.createOutFile(getRealPathFromURI(uri, this.ctx));
exif.writeExifData();
bitmap.recycle();
bitmap = null;
System.gc();
result = new PluginResult(Status.OK, uri.toString());
This is roughly the same logic as Phonegap uses. (I've removed all exception handling n all for posting. So assume there are no compile errors n all.) So, im basically trying to retrieve the Pic.jpg and return it to my phonegap app. BUT whats happening is that im getting a corrupted file of abt 150kb that isn't even a jpg (doesnt open).
Please tell me if its even possible to retrieve images in this manner after the activity that started the camera as died. And if its possible then, what am i doing wrong. Please help!
As I mentioned over in your other SO question,
phonegap android app crashing due to low memory on opening camera
the problem is most probably the Sony implementation of the camera intent. You should try testing by adding a third party camera app and when you take a picture select that app and see if it still crashes. It probably won't.
The issue here was because of some changed code in the FileTransfer plugin of Phonegap.
I was able to retrieve an image taken by the camera, after my app restarted after the crash using the above code only. :)

Send a picture to Facebook using Graph API on Android

I have been searching for this all day and just when I find something, I find it is not what I am looking for. In short, I am upgrading my app to use the Facebook graph API for Android and the documentation is horrible. All I want is to upload a picture into the default album for the app. I have the following code:
Facebook f = new Facebook(APP_ID);
Bundle parameters = new Bundle();
parameters.putString("message", caption);
parameters.putByteArray("picture", data);
f.dialog(mContext, "publish.stream", parameters, this); //TODO: This is wrong
I think the publish.stream is what is the problem because the exception that I got when I did my "this doesn't have a prayer" test was a malformedURLException.
Can someone tell me if I am even on the right track?
Thanks,
Jake

Categories

Resources