Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Share Intent callback result

I am using this method to call share my feed data:

    public void shareFeed() {
        try {
            Intent intent = new Intent(android.content.Intent.ACTION_SEND);
            intent.setType("text/plain");
            intent.putExtra(Intent.EXTRA_SUBJECT, "SUB");
            intent.putExtra(Intent.EXTRA_TEXT, "Body");
            startActivityForResult(Intent.createChooser(intent, "Choose an Email client :"), 1);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

and here's my onActivityResult code but I got data every time null in either success or fail :

  @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == 1) {
        if (resultCode == RESULT_OK) {
        }
    }
}

I want to perform call web-service after success so I need the share intent callback result.

like image 906
Akshay Chopde Avatar asked Sep 20 '16 11:09

Akshay Chopde


2 Answers

ACTION_SEND does not return any form of result. Quoting the documentation:

Output: nothing

There is no point in using startActivityForResult(), and you will not get a result.

On API Level 22 (Android 5.1) and higher devices, you are welcome to use the createChooser() variant that takes an IntentSender as a parameter. This will let you know what choice the user made out of the chooser. However:

  • That will not tell you if the user sent anything

  • I do not think that you find out anything if the user just abandons the chooser (though you might interpret the absence of a choice as indicating abandonment)

like image 155
CommonsWare Avatar answered Sep 20 '22 12:09

CommonsWare


The documentation for ACTION_SEND indicates that is generates no output (ie: generates no result).

like image 45
Sahil Avatar answered Sep 22 '22 12:09

Sahil