上传包含在URL中Facebook在Android上的图像 [英] upload a image contained in a url to Facebook in android

查看:143
本文介绍了上传包含在URL中Facebook在Android上的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的code,在图像上传到我的Facebook墙上。

I used the following code, to upload a image to my Facebook wall.

    try {
    bitmap=BitmapFactory.decodeFile(imagePostion);
    HttpClient httpClient = new DefaultHttpClient();
    HttpContext localContext = new BasicHttpContext();
    HttpPost httpPost = new HttpPost(
   "https://graph.facebook.com/me/photos?access_token="+ a);
    MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    bitmap.compress(CompressFormat.PNG, 100, bos);
    byte[] data = bos.toByteArray();
    entity.addPart("source", new ByteArrayBody(data, imagePostion));
    httpPost.setEntity(entity);
    HttpResponse response = httpClient.execute(httpPost,localContext);
    Log.v("Response !!!!!!!!",response+"");
    } catch (UnsupportedEncodingException e) {
    // TODO Auto-generated catch block
    e.printStackTrace()
    } catch (ClientProtocolException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

和我得到空指针异常此行

And I got null pointer exception at this line

ByteArrayOutputStream BOS =新ByteArrayOutputStream();

ByteArrayOutputStream bos = new ByteArrayOutputStream();

需要帮助。

推荐答案

最后,我得到它的工作。该MultipartEntity工作在Android 2.1的起。我曾试图在1.6。这就是为什么我得到了这个错误。

Finally I get it work. The MultipartEntity works in Android 2.1 onwards. I had tried in 1.6. That is why I got that error.

这篇关于上传包含在URL中Facebook在Android上的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆