如何使用默认的android共享(意图)将文本分享到Facebook?

时间:2016-02-01 08:53:29

标签: android facebook android-intent

我正在所有默认可用应用中进行文本共享,例如facebook,gmail..etc。

我在这里放了代码的快照。

final Intent emailIntent1 = new Intent(
            android.content.Intent.ACTION_SEND);
    emailIntent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    emailIntent1.setAction("https://play.google.com/store");
    emailIntent1.putExtra(Intent.EXTRA_TEXT,"https://play.google.com/store");
    emailIntent1.setType("image/png");
    startActivity(Intent.createChooser(emailIntent1, "send"));

我的问题是,我不能在Facebook上分享文字。

您的回答将不胜感激。

2 个答案:

答案 0 :(得分:2)

试试这个......

 Intent shareIntent = new Intent(Intent.ACTION_SEND);
        shareIntent.setType("text/plain");
        shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Share this app");
        String shareMessage = "https://play.google.com/store";
        shareIntent.putExtra(Intent.EXTRA_TEXT, shareMessage);
        startActivity(Intent.createChooser(shareIntent, "Choose the messenger to share this App"));

答案 1 :(得分:0)

试试这段代码。它将创建一个Intent Chooser,列出接受类型" text / plain"的设备上所有已安装的应用程序。

private void share(String text) {
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setType("text/plain");
    shareIntent.putExtra(Intent.EXTRA_TEXT, text);
    startActivity(Intent.createChooser(shareIntent, "Share text"));
}