I am creating an app in which there is a Gmail button and when user when clicks on Gmail it sends a mail to the particular receipient using inbuilt gmail client but what happens is when the user clicks on gmail button ,it opens a list of all the clients installed in the device eg hike,drive,email,gmail,etc with users asking for the option.
Here is my code
protected void sendEmail() {
Log.i("Send email", "");
String[] TO = {""};
String[] CC = {""};
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("message/rfc822"); //should i have to change this line of code
emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
emailIntent.putExtra(Intent.EXTRA_CC, CC);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Your subject"); //message subject
emailIntent.putExtra(Intent.EXTRA_TEXT, "Email message goes here"); //message content
try {
startActivity(Intent.createChooser(emailIntent,"Send mail..."));
finish();
Log.i("Finished sending email.", "");
}
catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MailSenderActivity.this, "There is no email client installed.", Toast.LENGTH_SHORT).show();
}
}
What I want is when user clicks on the Gmail button it only opens inbuilt Gmail and Email clients only not hike and all. How can I acheive this (by changing the type or what?). I have tried so many ways but in vain.
You can use the below code to redirect to Gmail Without asking for other email application