Home » Android » facebook – How to confirm Android Share Intent is successful or complete

facebook – How to confirm Android Share Intent is successful or complete

Posted by: admin June 15, 2020 Leave a comment

Questions:

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));
How to&Answers:

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.

Answer:

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

    }