Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to confirm Android Share Intent is successful or complete

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));
like image 345
code Avatar asked Dec 02 '14 03:12

code


2 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.

like image 151
Jawad Avatar answered Nov 18 '22 07:11

Jawad


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

    }
like image 1
Ravish kumar Avatar answered Nov 18 '22 06:11

Ravish kumar