オプションメニューを作りました。メールの送信を処理するボタンの 1 つが機能していません。
メソッドは次のとおりです。
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"));
}
フィールドはまだ自動入力されていません..