开发者

Toast after e-mail been sent in android

I've been trying for a long time to get an alert, like the toast, to come up after the user has clicked on send button, and the e-mail has been sent. My code seem to be correct, but the toast don't show up. I've been searching a lot to get it right, but I'm stuck. Any help would be appreciated!

Regards Anders

//My code

public class 开发者_如何学Cmailer extends Activity {


private Button clickBtn;

@Override    
public void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);  
  clickBtn = (Button) findViewById(R.id.button1);
  //clickBtn.setText("Skicka info!");

  clickBtn.setOnClickListener(new OnClickListener() {

  @Override    
  public void onClick(View v) {

    Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);    
    String[] recipients = new String[]{"donald@oo.se","laura@oo.se"};    
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients);
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Applikationsutveckling Android");    
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Jag vill veta mer om utbildningen!");    
    emailIntent.setType("text/plain");
    startActivityForResult(Intent.createChooser(emailIntent, "Skicka e-post..."),1);    

}
});
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        if (requestCode == 1) {
            Toast.makeText(mailer.this, 
                    "Tack för din intresseanmälan!", 
                    Toast.LENGTH_SHORT).show();
        }
    }
}


}


Sorry, you might need to find something else, but I don't believe you'll be able to make this work. As far as I can tell the default Android email programs (Gmail, Email) typically return prior to the actual transmission of the email, and in any case generally do not communicate using the onActivityResult pattern.


try this ..

if(requestCode==1 && resultCode==Activity.RESULT_OK)    
        {
            Toast.makeText(Activity, "Mail sent.", 
                              Toast.LENGTH_SHORT).show();

        }
        else if (requestCode==1 && resultCode==Activity.RESULT_CANCELED)
        {
            Toast.makeText(Activity, "Mail canceled.", 
                                Toast.LENGTH_SHORT).show();

        }
        else 
        {
            Toast.makeText(Activity, "Plz try again.", 
                               Toast.LENGTH_SHORT).show();

        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜