Android share intent for Facebook

2020-02-01 02:59发布

I have some problem with below code. This code is working for email, message, Twitter (for sending the text) but not for Facebook. Why?

Intent i=new Intent(android.content.Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(android.content.Intent.EXTRA_SUBJECT,"ScribeAir");
i.putExtra(android.content.Intent.EXTRA_TEXT, "ScribeAir has some cool features. Just use it...");
startActivity(Intent.createChooser(i,"Share"));

4条回答
我想做一个坏孩纸
2楼-- · 2020-02-01 03:32

this is not working for facebook because Facebook can share only a link via ACTION_SEND. if U want to send Text As well as link.

Firstly you have to get the list of installed application that support ACTION_SEND then buil a dialog

  Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
    sharingIntent.setType("text/plain");
    List activities = getPackageManager().queryIntentActivities(sharingIntent,0);

after the activities now build a dialog to show activities .then get the intent for facebook and share it with facebook api all other to be handled by itself but please pass the class name for other activities.

Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND); 
                sharingIntent.setClassName(,);
                sharingIntent.setType("text/plain");
                sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"hello");
                sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "facebook"); 
查看更多
再贱就再见
3楼-- · 2020-02-01 03:50
            Intent sharing = new Intent(android.content.Intent.ACTION_SEND); 
            sharing.setClassName(,);
            sharing.setType("text/plain");
            sharing.putExtra(android.content.Intent.EXTRA_SUBJECT,"hello");
            sharing.putExtra(android.content.Intent.EXTRA_TEXT, "yahoomail");
查看更多
趁早两清
4楼-- · 2020-02-01 03:50

Answering to question which is asked long long time ago..

As of i know, Facebook does not allow the Pre-populating of text through Intent unlike in the Twitter / Email. It by Facebook Default. But with the help of Facebook SDK, we can able to share text in the form of link.

Refer Facebook SDK sharing Docs

查看更多
女痞
5楼-- · 2020-02-01 03:54

try this:

i.setType("message/rfc822");
查看更多
登录 后发表回答