0

我建立了一个选项菜单。它处理发送电子邮件的按钮之一不起作用。

以下是方法:

public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main_page, menu);
        return true;
    }

public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.settings: Toast.makeText(this, "You pressed the settings!", Toast.LENGTH_LONG).show();
                                break;
            case R.id.exit:     System.exit(0); //close the program + kill it from memory
                                break;
            case R.id.contactUs:sendEmail();
                                break;
        }
        return true;
    }

private void sendEmail(){
        Intent mailIntent = new Intent();
        mailIntent.setAction(Intent.ACTION_SEND);
        mailIntent.setType("text/plain");
        mailIntent.putExtra(mailIntent.EXTRA_EMAIL, new String[]{"some_email@gmail.com"});
        mailIntent.putExtra(mailIntent.EXTRA_SUBJECT,"Re:Your Application");
    }

出于某种原因,我点击的任何项目,除了 contactUs 项目,都在工作。当我单击contactUs 项目时,它会关闭菜单栏并且什么也不做......

需要帮忙。

编辑:

我更改了以下内容:

private void sendEmail(){
    Intent mailIntent = new Intent();
    mailIntent.setAction(Intent.ACTION_SEND);
    mailIntent.setType("text/plain");
    mailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"some_email@gmail.com"});
    mailIntent.putExtra(Intent.EXTRA_SUBJECT,"Re:Your Application");
    startActivity(Intent.createChooser(mailIntent, "some_email@gmail.com"));
}

这些字段仍然没有自动填充..

4

2 回答 2

5

你必须打电话

startActivity(Intent.createChooser(mailIntent, "Choose an Email client :"));

编辑:

更改这些行

mailIntent.putExtra(mailIntent.EXTRA_EMAIL, new String[]{"some_email@gmail.com"});
mailIntent.putExtra(mailIntent.EXTRA_SUBJECT,"Re:Your Application");

mailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"some_email@gmail.com"});
mailIntent.putExtra(Intent.EXTRA_SUBJECT,"Re:Your Application");

编辑:

完整的方法应如下所示:

private void sendEmail(){
    Intent mailIntent = new Intent();
    mailIntent.setAction(Intent.ACTION_SEND);
    mailIntent.setType("text/plain");
    mailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"some_email@gmail.com"});
    mailIntent.putExtra(Intent.EXTRA_SUBJECT,"Re:Your Application");
    startActivity(Intent.createChooser(mailIntent, "Choose an Email client:"));
}
于 2012-12-12T12:08:30.360 回答
2

您需要致电:

startActivity(Intent.createChooser(mailIntent,"Choose E-mail client:"));
于 2012-12-12T12:09:15.093 回答