gpt4 book ai didi

android - 如何从sdcard上传图片到facebook

转载 作者:行者123 更新时间:2023-11-30 03:37:23 24 4
gpt4 key购买 nike

我已经使用 Facebook SDK 完成了文本共享。我坚持从 SD 卡上传图像。在将图像解析为 FB SDK 之前,首先我将图像转换为位图,然后我应该与 Facebook 共享。但是这个逻辑是行不通的。它从不从 SD 卡上传图像。谁能指导我如何从 SD 卡上传图像?提前致谢。

Bitmap bi = BitmapFactory.decodeStream(fis);
Bitmap bi =BitmapFactory.decodeFile(Environment.getExternalStorageDirectory() +"/Android/test.jpg", options);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);

最佳答案

尝试下面的代码并检查你的位图不应该为空..

Bundle bundle = new Bundle();
bundle.putString("message", "post image.." );

byte[] data = null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
<<your bitmap>>.compress(Bitmap.CompressFormat.JPEG, 100, baos);
data = baos.toByteArray();

bundle.putString(Facebook.TOKEN, facebook.getAccessToken());
bundle.putString("method", "photos.upload");
bundle.putByteArray("picture", data);
bundle.putString("message", "post image.." );

mAsyncRunner.request(null,bundle,"POST",new RequestListener() {
@Override
public void onMalformedURLException(MalformedURLException e, Object state) {
Log.d("request RequestListener", "debug onMalformedURLException");
}
@Override
public void onIOException(IOException e, Object state) {
Log.d("request RequestListener", "debug onIOException");
}
@Override
public void onFileNotFoundException(FileNotFoundException e, Object state) {
Log.d("request RequestListener", "debug onFileNotFoundException");
}
@Override
public void onFacebookError(FacebookError e, Object state) {
Log.d("request RequestListener", "debug onFacebookError");
}
@Override
public void onComplete(String response, Object state) {
Log.d("request RequestListener", "debug onComplete");
}
}, null);

关于android - 如何从sdcard上传图片到facebook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16434097/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com