Only Email apps to resolve an Intent

后端 未结 14 1591
执念已碎
执念已碎 2020-12-03 06:30

I have a problem .. I want only email activities to resolve intent ACTION.SEND but beside email I get other apps as well (e.g TubeMate) even though I have set the mime type

14条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-03 07:27

    u can also use:

    //writes messages only to email clients
    public void setWriteEmailButton() {
        btnWriteMail.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                Intent i = new Intent(Intent.ACTION_SENDTO);
                i.setData(Uri.parse("mailto:"));
                i.putExtra(Intent.EXTRA_EMAIL  , new String[]{mConsultantInfos.getConsultantEMail()});
                i.putExtra(Intent.EXTRA_SUBJECT, mContext.getString(R.string.txtSubjectConsultantMail));
                i.putExtra(Intent.EXTRA_TEXT   , "");
                try {
                    startActivity(Intent.createChooser(i, mContext.getString(R.string.txtWriteMailDialogTitle)));
                } catch (android.content.ActivityNotFoundException ex) {
                    UI.showShortToastMessage(mContext, R.string.msgNoMailClientsInstalled);
                }
            }
        });
    }
    

    have fun (combination of both ;))

提交回复
热议问题