4

I'm using next code for sharing:

Intent sendIntent = new Intent(Intent.ACTION_SEND); 
sendIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.share_text));
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
sendIntent.setType("image/png");
startActivityForResult(Intent.createChooser(sendIntent,
    getResources().getString(R.string.share_via)), REQUEST_SHARE_RESULT);

And I want checking result for this intent in my onActivityResult() function. But it's always return Activity.RESULT_CANCELED. Even sharing was successed. Why???

Ali Imran
  • 8,927
  • 3
  • 39
  • 50
Vlad B
  • 59
  • 5

2 Answers2

-1

In your child activity, you must call setResult() before calling finish(); this is how the child returns its result to the parent's onActivityResult() method.

mah
  • 39,056
  • 9
  • 76
  • 93
  • 1
    I'm know about it. My task is get sharing results from Gmail, Twitter and others. I can't using setResult() for them... I'm want to know result was successed or sharing operation was cancelled by user. – Vlad B Dec 05 '12 at 04:31
  • @mah, I am still looking for answer for the same. My app name is ABC and I am sharing data from app ABC to Facebook or WhatsApp. Now how will app ABC will know that data was shared to Facebook or WhatsApp using the method `createChooser`? Now I would recommend a link which shows alternate way http://stackoverflow.com/questions/9730243/how-to-filter-specific-apps-for-action-send-intent-and-set-a-different-text-for – Jimit Patel May 03 '16 at 15:11
  • ok then according to you what is the output when you use the function `Intent.createChooser()`. Try out – Jimit Patel May 03 '16 at 15:18
-1

try this example for startActivityForResult(). http://saigeethamn.blogspot.in/2009/08/android-developer-tutorial-for_31.html, http://android.rahulblogs.com/android-startactivityforresult-example/

kumar_android
  • 2,273
  • 1
  • 21
  • 30
  • I cannot set `setResult` which those tutorials suggested. I am sharing my data via Gmail, WhatsApp, etc. where I cant use `setResult` – Jimit Patel May 03 '16 at 11:47
  • @mah, now you taking it personally. And there is a function named `createChooser` which shows the list of other apps and where I cannot put the function `setResult` in other app than mine – Jimit Patel May 03 '16 at 15:14
  • @mah just final comment. I don't think there is any use to argue with you. Have you ever used the method `Intent.createChooser`? If no then use it once, then compare your answer. Also read the comment of the user on your reply who posted the question. Abusing or not I don't know but I'm sure you just arguing for getting vote down on your reply. You are just revenge seeker for me – Jimit Patel May 03 '16 at 15:39