Android Studio : while email sending and running the app on phone the app is not detecting any other mail sending apps?

83 Views Asked by At

I am just a beginner in app dev and referring the documentation wanted to build an email sending app using Implicit Intents. this works well when we write

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("*/*");

but when we write the following code to filter out only the mailing app it makes a toast saying that No app is installed which i have made in order to prevent my app from misbehaving.

Below is the simple code pls read it for once

    package com.example.emailsender;
//necessary imports

public class MainActivity extends AppCompatActivity {
//necessary variables edittext em, subject& button sub(submit)

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    em = findViewById(R.id.editTextTextEmailAddress);


    subject = findViewById(R.id.sub);
    sub = findViewById(R.id.button);

    sub.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String ema=em.getText().toString();
            String emails[]=ema.split(",");
            String s = subject.getText().toString();
            Intent intent = new Intent(Intent.ACTION_SENDTO);
            intent.setData(Uri.parse("mailto:"));
            intent.putExtra(Intent.EXTRA_EMAIL, emails);
            intent.putExtra(Intent.EXTRA_SUBJECT, s);
            if (intent.resolveActivity(getPackageManager()) != null) {
                startActivity(intent);
            }
            else
                Toast.makeText(MainActivity.this, "No app is installed", Toast.LENGTH_SHORT).show();
        }

    });
}

}

0

There are 0 best solutions below