9

Is there a way to confirm if a Share intent in Android was successful or unsuccessful? (For example, if I share a Facebook post, I'd like to know if it was successfully posted or know if it was cancelled.)

Below is the Android intent code that I use to Share. Currently, it launches a dialog to allow the user to choose which app to share to:

Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);    
activity.startActivity(Intent.createChooser(shareIntent, title));
code
  • 5,294
  • 16
  • 62
  • 113

2 Answers2

14

Personally, I was about to say "use startActivityForResult()" and check what gets returned. However, as you can read more here, it's not as simple as that. If the intent is cancelled by the user, the same number is returned as if the intent was completed (for most appications).

Ultimately, at the moment for a simpler Share intent in general, you cannot check if it's successful or not.

Community
  • 1
  • 1
DragonJawad
  • 1,846
  • 3
  • 20
  • 28
  • Thank you for the answer MDragon. If I want to specifically use Facebook/Twitter/E-mail for the share intent, how can I confirm if the share was successful? – code Dec 02 '14 at 03:33
  • For general share intents, you'll have to test all three of those out and see what they return for success and cancel. Twitter works at the very least, but as for Facebook, I doubt it does. – DragonJawad Dec 02 '14 at 05:21
  • Now, this is *conjecture* and outside of the scope of this question, but "specific intents" may work. However, what kind of specific intents/activities are there that link to the Facebook+Twitter(+Email?) APIs and then return a value for success or failure? In other words, there's the possibility that - if you want to know if those succeed - you'll need to handle it yourself. However, if there are already specific intents (or activities) made for those purposes, use those. – DragonJawad Dec 02 '14 at 05:24
  • 1
    I want to call api after user share successfully. so what i do ? Please help. – Ganpat Kaliya May 05 '17 at 05:33
1

In case of FacebookShareDialog Build your dialog with requestCode then onActivity check the Request code and Result code. For this there is one class in Facebook Sdk Name UiLifecycleHelper

in onCreate Method

uiHelper = new UiLifecycleHelper(this, null);
uiHelper.onCreate(savedInstanceState);




 FacebookDialog fbShardialog = new FacebookDialog.ShareDialogBuilder(
                        MainActivity.this)
                        .setLink("http://www.claro.com.ar/")
                        .setPicture("imagepath").setRequestCode(12)
                        .build();

                uiHelper.trackPendingDialogCall(fbShardialog.present());



OnActivityResult


 if (requestCode == 12) {
        if (resultCode == RESULT_OK) {
            //  show sucess message

        }
 else
//show failure message

    }
Nazik
  • 8,696
  • 27
  • 77
  • 123