Android share text to other application with ACTION_SEND

769 Views Asked by At

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();
    }
}
1

There are 1 best solutions below

4
On

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