3

I am trying to set up social sharing. It is working fine by showing all the available options when I select to share. But is there anyway I can check if the user selected 'Facebook' as their method of sharing cos I want to fire the relevant facebok sdk related codes when that happens. It seems facebook has limitation on what can be posted if I do not take their SDK route unlike other share options.

@Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if(id == R.id.social_share){
            //working - this opens up available sharing options on device.
            Intent i = new Intent(Intent.ACTION_SEND);
            i.setType("text/plain");
            i.putExtra(android.content.Intent.EXTRA_SUBJECT, "A Title"); 
            i.putExtra(Intent.EXTRA_TEXT, "This is content... ");
            startActivity(i.createChooser(i, "Share"));

            //I want to use this code if facebook is selected.
            if (ShareDialog.canShow(ShareLinkContent.class)) {
                ShareLinkContent linkContent = new ShareLinkContent.Builder()
                        .setContentTitle("Hello Facebook")
                        .setContentDescription(
                                "The 'Hello Facebook' sample  showcases simple Facebook integration")
                        .setContentUrl(Uri.parse("http://developers.facebook.com/android"))
                        .build();
                        .setImageUrl(Uri.parse("http://....."))
                shareDialog.show(linkContent);
            }
        }
        return true;
    } 
Trevor_zam
  • 592
  • 2
  • 7
  • 21

1 Answers1

1

There is no direct way to identify which app was selected using ACTION_SEND intent. You will need to write a custom application chooser dialog to determine which one the user selects. Check this post to see a few which have been written by other users as answer to a similar question.

Community
  • 1
  • 1
Viral Patel
  • 32,418
  • 18
  • 82
  • 110