Skip to content Skip to sidebar Skip to footer

Detect Email Sent Or Not In Onactivity Result

I want to detect whether person has send the email or pressed back button or discarded it, in my onActivityResult Method. How can I do the same. I am doing it like this String[] re

Solution 1:

After reading tones of staff on this issue I understood that there is no way to know exactly if the user pressed "Send" or just canceled.

But there is a way to find out at least if the user has opened any mail client application or pressed back from the "Complete action using" dialog. (In my case I just wanted to finish activity if the user opened mail client and do nothing if the user pressed back from the dialog). The trick is very simple.

As the dialog is a floating window, when it is being shown over the activity, only the onPause() method is being called in activity, but when the user chose a mail client and it is being opened the onStop() method of activity is also being called. So you can start ACTION_SEND with startActivityForResult() :

startActivityForResult(intent, CODE_SEND);

and also have a boolean flag that you will change in onPause() and onStop():

publicclassMainActivityextendsActivity {
...

privateboolean mailClientOpened = false;

@OverrideprotectedvoidonResume() {
   super.onResume();
   mailClientOpened = false;
}

@OverrideprotectedvoidonStop() {
    super.onStop();
    mailClientOpened = true;
}

and in your onActivityResult() you can check the requestCode and the boolean mailClientOpened to know if the client was opened or user canceled the dialog:

@OverridepublicvoidonActivityResult(int requestCode, int resultCode, Intent data) {
    if(requestCode == CODE_SEND && mailClientOpened){
    finish(); // Or do something else that you need to do when you know that user at least opened the mail client app
        }
    }

P.S. I know that this is not an exact answer to the question but I hope this can be useful to someone.

Solution 2:

as per this link

  • You can't, this is not part of the API. It returns once you have pressed send button even if it is not sent

Not sure but You are getting the for RESULT_CANCELED because it looks it is default it user not set Result ok then it consider RESULT_CANCELED and email activity never sets result RESULT_OK so it takes as RESULT_CANCELED .

  • You can check it by cheeking Intent data coming back will always null either mail send or discard.

Solution 3:

This may help you

StringDELIVERED="SMS_DELIVERED" + serialnum; // Unique ACTION every timeIntentdelivered=newIntent(context, MessageStatusReceiver.class);
delivered.setAction(DELIVERED ); // Set action to ensure unique PendingIntent
delivered.putExtra("MsgNum", serialnum);
PendingIntentdeliveredPI= PendingIntent.getBroadcast(this,
Integer.parseInt(serialnum), delivered,
PendingIntent.FLAG_ONE_SHOT);

Reference:Differentiating delivery reports of two separate SMS's

Post a Comment for "Detect Email Sent Or Not In Onactivity Result"