Я пытаюсь, чтобы мое приложение отправило новый пароль на один адрес электронной почты, но открывает страницу и дает сообщение «Никакие приложения не могут выполнить это действие» с заголовком «Отправить письмо» (который у меня есть, я знаю) , Зачем? Идея с новым паролем - это то, что я хочу, но сначала я хочу отправить что-либо в напечатанное письмо в edittext, чтобы проверить его. Я попытался запустить его на реальном устройстве.Как правильно использовать emailintent?
public class Glemtpassword extends AppCompatActivity implements View.OnClickListener{
Button nypassword;
EditText email;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_glemtpassword);
nypassword = (Button) findViewById(R.id.nypassword);
nypassword.setOnClickListener(this);
email = (EditText) findViewById(R.id.email);
}
@Override
public void onClick(View view) {
if (view == nypassword){
sendEmail();
}
}
protected void sendEmail() {
Log.i("Send email", "");
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_EMAIL, String.valueOf(email));
try {
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
finish();
Log.i("Nyt password er sendt til din mail...", "");
}
catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(Glemtpassword.this, "Ingen email klient", Toast.LENGTH_SHORT).show();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.Forside) {
Intent intent = new Intent(this, Forside.class);
startActivity(intent);
}
else if (id == R.id.Logind){
Intent intent = new Intent(this, LogInd.class);
startActivity(intent);
}
else if (id==R.id.Opretbruger) {
Intent intent = new Intent(this, OpretBruger.class);
startActivity(intent);
}
return true;
}
}
EDIT:
public class Glemtpassword extends AppCompatActivity implements View.OnClickListener{
Button nypassword;
EditText email;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_glemtpassword);
nypassword = (Button) findViewById(R.id.nypassword);
nypassword.setOnClickListener(this);
email = (EditText) findViewById(R.id.email);
}
@Override
public void onClick(View view) {
if (view == nypassword){
sendEmail();
}
}
protected void sendEmail() {
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
"mailto", email.getText().toString(), null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Body");
startActivity(Intent.createChooser(emailIntent, "Send email..."));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.Forside) {
Intent intent = new Intent(this, Forside.class);
startActivity(intent);
}
else if (id == R.id.Logind){
Intent intent = new Intent(this, LogInd.class);
startActivity(intent);
}
else if (id==R.id.Opretbruger) {
Intent intent = new Intent(this, OpretBruger.class);
startActivity(intent);
}
return true;
}
}
Проверьте это: http://stackoverflow.com/a/2033124/4350275 –