0

i don't understand where mistake I'm basically trying to do so that when I click the button "fb" the application open a share on facebook by including the link, but as soon as I test, it opens the facebook page without links? could you help me? I'd like to know if you can also enter a fixed text, along with the link (if it is possible you might see me with lines of code)? thanks

this is the code

final Button button = (Button) findViewById(R.id.fb);
button.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {

        String urlToShare = "https://www.google.it/?gfe_rd=cr&ei=IysDVMyHPMjD8gesvYH4DA";
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/plain");
        // intent.putExtra(Intent.EXTRA_SUBJECT, "Foo bar"); // NB: has no effect!
        intent.putExtra(Intent.EXTRA_TEXT, urlToShare);

        // See if official Facebook app is found
        boolean facebookAppFound = false;
        List<ResolveInfo> matches = getPackageManager().queryIntentActivities(intent, 0);
        for (ResolveInfo info : matches) {
            if (info.activityInfo.packageName.toLowerCase().startsWith("com.facebook.katana")) {
                intent.setPackage(info.activityInfo.packageName);
                facebookAppFound = true;
                break;
            }
        }

        // As fallback, launch sharer.php in a browser
        if (!facebookAppFound) {
            String sharerUrl = "https://www.facebook.com/sharer/sharer.php?u=" + urlToShare;
            intent = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl));
        }

        startActivity(intent);
User777
  • 15
  • 1
  • 1
  • 8

2 Answers2

0
The Facebook application does not handle either the EXTRA_SUBJECT or EXTRA_TEXT fields.

Here is bug link : https://developers.facebook.com/bugs/332619626816423

The thing is, if you put a URL in the EXTRA_TEXT field, it does work. It's like their intentionally stripping out any text

EDIT: The newest Facebook versions doesn't allow you to share text using intents. You have to use the Facebook SDK to do it - to make that simple, use the Facebook SDK + Android Simple Facebook (https://github.com/sromku/android-simple-facebook).

Jamil
  • 5,457
  • 4
  • 26
  • 29
  • check my edit... also see this link http://stackoverflow.com/questions/22533773/android-how-to-share-image-with-text-on-facebook-via-intent – Jamil Aug 31 '14 at 14:32
-1

This below code for all social network you can shared:

        Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
        sharingIntent.setType("text/plain");
        sharingIntent.putExtra(Intent.EXTRA_TEXT,urlToShare);
        startActivity(Intent.createChooser(sharingIntent,"Şhare"));
ferandro
  • 3
  • 3