I'm trying to let my app send a new password to ones email but it opens a page and gives the message "No apps can perform this action" with the title "Send email" (which I've have I know), why? The idea with a new password is what I want, but first I want to send anything to the typed email in the edittext to test it. I've tried to run it on a real device.
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;
}
}