如何在Facebook上分享我的应用程序的imageswitcher图像?
问题描述:
我正在为Android制作应用程序。我有一个照片库,我想提供在Facebook上点击按钮(仅当前显示的照片)共享图像切换器的可能性。我怎样才能做到这一点?如何在Facebook上分享我的应用程序的imageswitcher图像?
谢谢!
答
如果你熟悉的Facebook SDK为Android,试试这个:
//Getting the image
Bitmap bm = theImageViewToUpload.getDrawingCache();
byte[] bArray = null;
ByteArrayOutputStream baoStream = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 100, baoStream);
bArray = baoStream.toByteArray();
Bundle bund = new Bundle();
bund.putString(Facebook.TOKEN, access_token);
bundle.putString("caption", "This is your image-caption on Facebook");
bund.putByteArray("picture", bArray);
//Uploading to Facebook
try {
fb.request("me/photos", bund, "POST");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
如果你不熟悉Facebook的SDK,我不是在这里教你一个答案的一切计划,但看看他们的参考:http://developers.facebook.com/docs/reference/androidsdk/
编辑:将此代码添加到您打算使用的按钮的onClick。
+0
好吧,我会尝试它!非常感谢! :) – imtheuser 2012-08-20 15:55:37
你试过了什么? – 2012-08-16 10:18:12