1

「メニュー」ボタンからどのようにメールを送信しますか?「送信」というオプションでメニューを膨らませました。押すと、Intent.ACTION_SENDが開き、ユーザーは私にメールを送信することを選択できます。

ButtonとOnClickListenerを介してこれを実現する方法を知っています。しかし、メニューを通してではありません。以下に貼り付けたコードは機能しません。私は何が間違っているのですか?

お時間をいただきありがとうございます。

CustomStoreActivity:

    public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.customstore_menu, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.send:

        Intent i = new Intent(Intent.ACTION_SEND);
        i.setType("text/plain");
        i.putExtra(Intent.EXTRA_EMAIL,
                new String[] { "myemail@myemail.com" });
        i.putExtra(Intent.EXTRA_SUBJECT, "Adding new shop to MinuteMap");
        i.putExtra(Intent.EXTRA_TEXT, "nll");
        // shopName + shopTimeM1);

        break;

    default:
        return super.onOptionsItemSelected(item);
    }
    return true;

}
4

2 に答える 2

3

以下のコードを使用できます :::

Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL, new String[] { "myemail@example.com" });
i.putExtra(Intent.EXTRA_SUBJECT, "Adding new shop to MinuteMap");
i.putExtra(Intent.EXTRA_TEXT, "nll"); 
startActivity(i);
于 2012-04-21T02:12:06.287 に答える
2

このコードを試してください。

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
            emailIntent.setType("text/html");
            emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
                    new String[] { "abc@xyz.com" });

            emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                    "Subject of the Mail");
            emailIntent
                    .putExtra(
                            android.content.Intent.EXTRA_TEXT,
                            "This is my sample Mail");
            emailIntent.setType("vnd.android.cursor.dir/email");
            startActivity(Intent.createChooser(emailIntent, "Email:"));
于 2012-04-21T03:25:58.590 に答える