2

我正在使用发布提要对话框将文本和图像从 sdcard 发送到 facebook 墙我使用 facebook sdk 3.0 文本已成功发送到 facebook 墙但图像未发送我把我的代码放在这里你可以查看

选择图像.java

private void publishFeedDialog()
    {

        Bitmap bmp = BitmapFactory.decodeFile("/mnt/sdcard/abc.jpg");        
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);  // where bm is bitmap from Sdcard
        byte[] byteArray = stream.toByteArray();


        Bundle params = new Bundle();
        params.putString("name","abcd");
        params.putByteArray("source",byteArray);

        final WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(this, Session.getActiveSession(), params))
            .setOnCompleteListener(new OnCompleteListener()
        {

                @Override
                public void onComplete(Bundle values,FacebookException error)
                {
                    if (error == null)
                    {
                        // When the story is posted, echo the success
                        // and the post Id.

                        final String postId = values.getString("post_id");
                        if (postId != null) 
                        {

                         //   Toast.makeText(SearchListClickActivity.this,"Posted story, id: "+postId,Toast.LENGTH_SHORT).show();
                        } 
                        else
                        {
                            // User clicked the Cancel button
                         // Toast.makeText(this.getApplicationContext(),"Publish cancelled",Toast.LENGTH_SHORT).show();
                        }
                    }
                    else if (error instanceof FacebookOperationCanceledException)
                    {
                        // User clicked the "x" button
                      //  Toast.makeText(getActivity().getApplicationContext(),"Publish cancelled",Toast.LENGTH_SHORT).show();
                    } 
                    else 
                    {
                        // Generic, ex: network error
                      //  Toast.makeText(getActivity().getApplicationContext(),"Error posting story",Toast.LENGTH_SHORT).show();
                    }
                }

            })
            .build();
        feedDialog.show();
    }
4

0 回答 0