Calling a mail client when clicking a button

2019-06-01 18:21发布

I have a ListView connected to parse server data is coming through parse. when I click single item of the ListView it goes to single item view. there i have a button for email , what i need is when I click that email button and email client should open .with that particular single items email id . email id's are stored in a column in parse database . any one knows please tel how to do this ?

my database is parse server , I need to get emails dynamically from a parse column. each singe item has a different email ... email column name is "email"

*

I used an answer below and edited like this but no receiver email showing

*


edited code using below answer directing to mail client , but no receiver email showing

btn1 = (Button)findViewById(R.id.button5);
            btn1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    String phnoo = object.getString("email");


                    Intent intent = new Intent(Intent.ACTION_SENDTO);
                   intent.setType("message/rfc822");
                    intent.setData(Uri.parse("mailto:"+phnoo));
                    startActivity(intent);

my java code for calling email client

  btn1 = (Button) findViewById(R.id.button5) ;
        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String phno="email";

                Intent intent = new Intent(Intent.ACTION_VIEW);
                Uri data = Uri.parse("mailto:" +phno);
                intent.setData(data);
                startActivity(intent);
            }
        });

xml code for button

   <Button
            android:id="@+id/button5"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:text="E-MAIL"

            android:layout_weight="1"
            android:background="#EFEFEF"/>

3条回答
倾城 Initia
2楼-- · 2019-06-01 18:32

Try this

Intent i = new Intent(Intent.ACTION_SEND);
i.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{ emailAddress });
i.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
i.putExtra(android.content.Intent.EXTRA_TEXT, text);
startActivity(Intent.createChooser(i, "Send email"));
查看更多
【Aperson】
3楼-- · 2019-06-01 18:33

Try following

    private void sendEmail(File file){
            Intent emailIntent = new Intent(Intent.ACTION_SEND);
            emailIntent.setType("text/html");
            final PackageManager pm = this.getPackageManager();
            final List<ResolveInfo> matches = pm.queryIntentActivities(emailIntent, 0);
            String className = null;
            for (final ResolveInfo info : matches) {
                if (info.activityInfo.packageName.equals("com.google.android.gm")) {
                    className = info.activityInfo.name;

                    if(className != null && !className.isEmpty()){
                        break;
                    }
                }
            }
            emailIntent.setClassName("com.google.android.gm", className);
            emailIntent.setType("vnd.android.cursor.dir/email");
            emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
            emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"xyz@abc.com"});
            emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
            emailIntent.setType("plain/text");
            startActivity(emailIntent);

        }
查看更多
手持菜刀,她持情操
4楼-- · 2019-06-01 18:37

I think this would help you

Intent in = new Intent(Intent.ACTION_SEND);
in.setType("plain/text");
in.putExtra(Intent.EXTRA_EMAIL, new String[] { "mail id" });
in.putExtra(Intent.EXTRA_SUBJECT, "subject");
in.putExtra(Intent.EXTRA_TEXT, "mail body");
startActivity(Intent.createChooser(in, ""));
查看更多
登录 后发表回答