javaandroidandroid-studioonactivityresultsharefile

I want to get result from sharing a file on Android


I have to share a url on android default but i want a response if url is being shared or just intent is closed. I am using on activity result but when i share with gmail it return 0(CANCELED) same when i close the intent.I need this to set text shared on a text view.Here is my code.

public void executeShareLinkClick() {
   Intent intentShare = new Intent(ACTION_SEND);
    intentShare.setType("text/plain");
    viewModel.isLinkSharedOpen.set(true);
    intentShare.putExtra(Intent.EXTRA_TEXT,"My Text of the message goes here ... write anything what you want");
    startActivityForResult(Intent.createChooser(intentShare, "Shared the text ..."),111);
}

public void onActivityResult(int requestCode, int resultCode, @Nullable @org.jetbrains.annotations.Nullable Intent data) {
   if (resultCode==RESULT_OK){
       viewModel.isLinkShared.set(true);
   }else{
       viewModel.isLinkShared.set(false);
   }
    viewModel.isLinkSharedOpen.set(false);
}

Solution

  • Sorry, but what you want is not an option. ACTION_SEND does not support a result, and apps do not have to indicate whether or not the user sent your content.

    The closest thing you can do is to add EXTRA_CHOSEN_COMPONENT_INTENT_SENDER to the Intent returned by createChooser(). Through that, you can find out if the user chose something in that chooser. However: