0

I want to share a text to another application and want to if text successfully sent then result in code equal 1 and else result in code equal 0 and if result code equal 1 then do something but ACTION_SEND do not return anything.do you have an idea?

shareimg.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
            sharingIntent.setType("text/plain");
            sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, headertext.getText().toString() );
            sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, share );
            startActivityForResult(Intent.createChooser(sharingIntent, "به اشتراک گذاری "),sharerequstresultcode);
        }
    });

and onActivityResult:

protected void onActivityResult(int requestCode, int resultCode,
                                Intent data) {
    if (requestCode == sharerequstresultcode) {
        Toast.makeText(getApplicationContext(),"submit",Toast.LENGTH_SHORT).show();
    }
}
InsaneCat
  • 2,115
  • 5
  • 21
  • 40

1 Answers1

0

ACTION_SEND does not return a result ("Output: nothing" in the documentation), and so it is pointless to use it with startActivityForResult().

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

Faysal Ahmed
  • 7,501
  • 5
  • 28
  • 50
  • do you have idea to this problem? – ali sharghi Aug 14 '18 at 06:56
  • I have no idea about this. ACTION_SEND does not provide anything. So you need to think in different way. – Faysal Ahmed Aug 14 '18 at 07:11
  • While true that the documentation lists `Output: nothing` for this (and many other `ACTION_*` types), in testing using `onActivityResult` on the same activity I do get a call through to this method with a matching `requestCode` but it's not consistent. Selecting `Copy to clipboard` returns a `resultCode` of -1, `Bluetooth` and others 0. Doing it "too quickly" or cancelling out by clicking off the chooser seems to mean I don't get a call back to `onActivityResult`. – msbit Aug 14 '18 at 07:17
  • Oh, just realised that -1 is `Activity.RESULT_OK` and 0 is `Activity.RESULT_CANCELED` which actually makes sense given that for `Bluetooth` and others I'd not actually gone through and sent the text via bluetooth etc. – msbit Aug 14 '18 at 07:23