Facebook 使用 facebook sdk 从应用程序共享文本

Facebook share text from app with facebook sdk

我正在我的应用程序中实现共享。它必须是文本 share.all 应用程序可以很好地共享有意图的文本,但 facebook 不允许通过意图共享文本。所以我实现了它的 sdk 并写下了这段代码。

ShareContent linkContent = new ShareLinkContent.Builder()
                                    .setContentTitle("Hello Facebook")
                                    .setContentDescription(localThoughtDesc.get(finalI1))
                                    .setContentUrl(Uri.parse("https://www.google.com"))
                                    .build();

                            shareDialog.show(linkContent);

但我得到了这样的输出

我学习了很多教程。但其中大多数已被弃用。所以如果有人能帮助我,那就太好了。:)

谢谢:)

Facebook 分享不支持文本。您只能分享 link,这将在 Facebook 中与您的 link 一起显示该页面的 <meta content ="..."> 文本。

由于我无法通过任何方式 post Facebook 上的任何内容,所以我尝试了另一种方式 post 将文本发送到 Facebook。认为它可能有帮助。顺便说一下,它实际上并不是文本共享。我将文本转换为图像文件,而不是通过意图 posted 图像。 这是我的做法。

                 TextView textView=new TextView(getBaseContext());
                textView.setTag("textView");
                View view=innerLayout.findViewWithTag("textView");


                String SCREENSHOTS_LOCATIONS = Environment.getExternalStorageDirectory().toString() + "/screenshots/";
                Bitmap bitmap = Bitmap.createBitmap(view.getWidth(),view.getHeight(), Bitmap.Config.ARGB_4444);
                String path=SCREENSHOTS_LOCATIONS+ System.currentTimeMillis() + ".jpg";

                final Canvas canvas = new Canvas(bitmap);

                view.draw(canvas);
                System.out.println(bitmap.getHeight()+" "+bitmap.getWidth());
                FileOutputStream fos = null;
                try {
                    final File sddir = new File(SCREENSHOTS_LOCATIONS);
                    if (!sddir.exists()) {
                        sddir.mkdirs();
                    }

                    fos = new FileOutputStream(path);
                    System.out.println(sddir.getPath().toString());
                    if (fos != null) {
                        if (!bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos)) {
                            Log.d("abc", "Compress/Write failed");
                        }
                        fos.flush();
                        fos.close();
                    }

                } catch (FileNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                Intent intent=new Intent();
                intent.setAction(Intent.ACTION_SEND);
                intent.putExtra(Intent.EXTRA_TITLE, "Title");
                intent.putExtra(Intent.EXTRA_SUBJECT, "Extra Subject");
                intent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(new File(path))); //optional//use this when you want to send an image
                intent.setType("image/jpeg");
                intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                startActivityForResult(Intent.createChooser(intent, "send"), REQUEST_CODE);