从SD卡上传图片至Facebook [英] Upload image to FaceBook from SDCard
本文介绍了从SD卡上传图片至Facebook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
随着Android 2.1的我该怎么上传图片到Facebook的墙?这些图像存放在SD卡。
With Android 2.1 how can I upload an image on to a Facebook wall? The images are store in SDCard.
推荐答案
您应该使用Facebook的API的 http://developers.facebook.com/docs/guides/mobile/#android 。 然后用这个code:
You should use Facebook API http://developers.facebook.com/docs/guides/mobile/#android. And then use this code:
byte[] data = null;
try {
FileInputStream fis = new FileInputStream(PATH_TO_FILE);
Bitmap bi = BitmapFactory.decodeStream(fis);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
data = baos.toByteArray();
} catch (FileNotFoundException e) {
e.printStackTrace();
Log.d("onCreate", "debug error e = " + e.toString());
}
Bundle params = new Bundle();
params.putString("method", "photos.upload");
params.putByteArray("picture", data);
Facebook facebook = new Facebook(FACEBOOK_APP_ID);
AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
mAsyncRunner.request(null, params, "POST", new RequestListener() {
public void onMalformedURLException(MalformedURLException e, Object state) {
Log.d("request RequestListener", "debug onMalformedURLException");
}
public void onIOException(IOException e, Object state) {
Log.d("request RequestListener", "debug onIOException");
}
public void onFileNotFoundException(FileNotFoundException e, Object state) {
Log.d("request RequestListener", "debug onFileNotFoundException");
}
public void onFacebookError(FacebookError e, Object state) {
Log.d("request RequestListener", "debug onFacebookError");
}
public void onComplete(String response, Object state) {
Log.d("request RequestListener", "debug onComplete");
}
}, null);
请确保您的应用程序有权限互联网和SD卡读
Be sure you application has permission to internet and sdcard reading
这篇关于从SD卡上传图片至Facebook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文