使用SDK通过SharePhotoContent在Facebook中设置预填充文本内容

时间:2016-06-03 12:00:00

标签: facebook sdk

我需要在Facebook墙上发布文字和图片。为此,我不能使用意图共享,因为我也想分享文本。所以我实现了Facebook SDK。但我仍然无法在墙上看到我的文字内容/标题。这是我的代码。

 private void publishImage() {
    ArrayList<SharePhoto> sharePhotos = new ArrayList<>();
    int imageFolderSize;
    File  imageFolder = new File(getActivity().getExternalCacheDir(), "attachments/images");
    if( imageFolder.exists()) {
        imageFolderSize = imageFolder.listFiles().length;
        ArrayList<File> attachments = new ArrayList<>();
        if (imageFolder.exists()) {
            Collections.addAll(attachments, imageFolder.listFiles());
        }
        if (imageFolderSize > 0) {
            for (int i = 0; i < attachments.size(); i++) {
                File file = attachments.get(i);
                if (file.exists()) {
                    if (file.getAbsolutePath().endsWith(".png")) {
                        try {
                            SharePhoto photo = new SharePhoto.Builder().setBitmap(BitmapFactory.decodeFile(file.getAbsolutePath()))
                                    .setCaption("Welcome To Facebook Photo Sharing on steroids!")
                                    .build();
                            sharePhotos.add(photo);
                        }catch (Exception e){
                            RMLog.debug("Execp: e"+e.toString());
                        }
                    }
                }
            }
        }
    }
    SharePhotoContent scontent = new SharePhotoContent.Builder().addPhotos(sharePhotos ).build();
    if(ShareDialog.canShow(SharePhotoContent.class))
    {
        shareDialog.show(scontent);
        Toast.makeText(getActivity(), "Succsesfully posted on your wall",
                Toast.LENGTH_LONG).show();
    }
}

0 个答案:

没有答案