Tell me how to send a message to gmail so that only this application is called gmail

public class EmailActivity extends AppCompatActivity implements View.OnClickListener{ AppCompatButton send; EditText address,emailtext; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.emailactivity); send = (AppCompatButton) findViewById(R.id.send); send.setOnClickListener(new View.OnClickListener(){ public void onClick(View arg0){ Uri address = Uri.parse(""); Intent surf = new Intent(Intent.ACTION_VIEW, address); startActivity(surf); } }); send = (AppCompatButton) findViewById(R.id.send); address = (EditText) findViewById(R.id.editText); emailtext = (EditText) findViewById(R.id.editText1); send.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()){ case R.id.send: final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); emailIntent.setType("plain/text"); // Кому emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] {"******@gmail.com"}); emailIntent.putExtra(Intent.EXTRA_SUBJECT, address.getText().toString()); // О чём emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,emailtext.getText().toString()); startActivity(Intent.createChooser(emailIntent, "Отправка письма")); break; } } } 

When sending, there are many programs that can be sent with help, how to make it to be just gmail?

    1 answer 1

    Method for sending email:

     private void sendUsingGmail(Intent intent) { List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(intent, 0); if (!resInfo.isEmpty()){ for (ResolveInfo info : resInfo) { if (info.activityInfo == null) continue; if ("com.google.android.gm".equals(info.activityInfo.packageName)){ intent.setPackage(info.activityInfo.packageName); startActivity(intent); return; } } } startActivity(Intent.createChooser(emailIntent, "Отправка письма")); } 

    Using:

     Intent emailIntent = new Intent(Intent.ACTION_SEND); emailIntent.setType("plain/text"); emailIntent.putExtra(Intent.EXTRA_EMAIL,new String[] {"******@gmail.com"}); emailIntent.putExtra(Intent.EXTRA_SUBJECT, address.getText().toString()); emailIntent.putExtra(Intent.EXTRA_TEXT,emailtext.getText().toString()); sendUsingGmail(emailIntent); 

    Explanation:

    This method searches for installed applications with the com.google.android.gm package, which corresponds to the Gmail application package. When it finds it, it uses the Gmail application, and if not, it creates a standard choice of the application for sending the letter.