Is it possible to detect if an ACTION_SEND Intent suceeded?

前端 未结 2 1680
广开言路
广开言路 2021-01-19 03:20

I have a simple Android app with code like this (from the Android Documentation):

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);         


        
相关标签:
2条回答
  • 2021-01-19 03:28

    Is there a way to read an intent response?

    Not from an arbitrary activity for an arbitrary action.

    The documentation for Intent actions will tell you if there is expected output or not. So, for example, ACTION_GET_CONTENT is documented to have output. For those Intent actions, you use startActivityForResult(), and part of the output will be a "result code" to let you know generally what the result was.

    However:

    • Not every Intent action is documented to have output. Notably, ACTION_SEND is not documented to have output. In that case, you don't use startActivityForResult() (but instead use startActivity()). Even if you do use startActivityForResult(), you have no way to know if a negative outcome means that the user cancelled out or if the other activity simply is following the documentation and did not return a result.

    • Some activities are buggy and fail to return results when they should.

    • Your definition of a successful result and the activity's definition of a successful result may differ.

    0 讨论(0)
  • 2021-01-19 03:30

    I don't think there is an assured way to do it.

    You could initiate the send using startActivityForResult() and hope that the activity which handles the Intent replies with a RESULT_OK. But you can't rely on it to work always.

    AnD then you can check

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            Toast.makeText(this,"Successfully Sharing", Toast.LENGTH_SHORT).show();
    
        }
    }
    
    0 讨论(0)
提交回复
热议问题