I have a simple Android app with code like this (from the Android Documentation):
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
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.
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();
}
}