首页 > 解决方案 > 共享按钮不与 facebook 一起运行(文本为空)

问题描述

共享按钮与 Viber 和 What's 应用程序一起运行,但不与 Facebook 一起运行,只是空白区域。

Intent myIntent = new Intent(Intent.ACTION_SEND);
bt = findViewById(R.id.imageShareButton);
        bt.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                String shareBody = versesText.getText().toString();
                myIntent.setType("text/plain");
                myIntent.putExtra(Intent.EXTRA_SUBJECT, "Perfect Verses");
                myIntent.putExtra(Intent.EXTRA_TEXT, shareBody + "\n" + "Read More...");
                myIntent.putExtra(Intent.EXTRA_TEXT, shareBody);
                startActivity(Intent.createChooser(myIntent, getResources().getString(R.string.app_name)));
             }
         });

我的应用在 GooglePlay 上的链接, https://play.google.com/store/apps/details? id=com.samuel.perfectverses

标签: androidandroid-studioandroid-intentshare

解决方案


String packageName = "com.facebook.katana";
String fullUrl = "https://m.facebook.com/sharer.php?u=..";
        Intent intent = getPackageManager().getLaunchIntentForPackage(packageName);
        if (intent == null) {
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(fullUrl));
            startActivity(i);
        } else {
            Intent sharingIntent = new Intent(Intent.ACTION_SEND);
            sharingIntent.setClassName(packageName ,
                    "com.facebook.katana.ShareLinkActivity");
            sharingIntent.putExtra(Intent.EXTRA_TEXT, "your title text");
            startActivity(sharingIntent);

推荐阅读